Skip to content

Commit 2b29ce9

Browse files
authored
Merge pull request #11 from InteractiveGraphicsLab/DevModeFixMask
Improved processing of laplacian deformation
2 parents 60d1b3c + b48b76c commit 2b29ce9

6 files changed

Lines changed: 52 additions & 49 deletions

File tree

COMMON/LaplacianSurfaceEditing.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ void LaplacianDeformer::Deform(
3030

3131
m_times = 1;
3232

33-
if (!m_is_set_solver || m_fixed_verts_idxs != _fixed_verts_idxs)
34-
{
35-
SetSolver(_fixed_verts_idxs);
36-
}
33+
SetSolver(_fixed_verts_idxs);
3734
Solve(_fixed_positions);
3835

3936
std::cout << "deformed...\n";

RoiPainter4D/RoiPainter4D/FormFixMask.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ System::Void FormFixMask::m_btn_sharestroke_Click(System::Object^ sender, System
7878

7979

8080
System::Void FormFixMask::m_btn_loadstate_Click(System::Object^ sender, System::EventArgs^ e)
81+
{
82+
LoadState();
83+
}
84+
85+
86+
System::Void FormFixMask::m_btn_savestate_Click(System::Object^ sender, System::EventArgs^ e)
87+
{
88+
SaveState();
89+
}
90+
91+
92+
void FormFixMask::LoadState()
8193
{
8294
std::string fpath;
8395

@@ -99,7 +111,7 @@ System::Void FormFixMask::m_btn_loadstate_Click(System::Object^ sender, System::
99111
}
100112

101113

102-
System::Void FormFixMask::m_btn_savestate_Click(System::Object^ sender, System::EventArgs^ e)
114+
void FormFixMask::SaveState()
103115
{
104116
std::string fpath;
105117

RoiPainter4D/RoiPainter4D/FormFixMask.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ namespace RoiPainter4D {
361361
System::Void m_btn_savestate_Click(System::Object^ sender, System::EventArgs^ e);
362362
System::Void m_checkbox_showonlyselectedstroke_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
363363
public:
364+
void LoadState();
365+
void SaveState();
364366
int GetCPSize();
365367
bool GetShowOnlySelectedStroke();
366368
int GetMCScale();
@@ -369,6 +371,8 @@ namespace RoiPainter4D {
369371
inline void FormFixMask_Show() { FormFixMask::GetInst()->Show(); }
370372
inline void FormFixMask_Hide() { FormFixMask::GetInst()->Hide(); }
371373
inline void FormFixMask_InitAllItems() { FormFixMask::GetInst()->InitAllItems(); }
374+
inline void FormFixMask_LoadState() { FormFixMask::GetInst()->LoadState(); }
375+
inline void FormFixMask_SaveState() { FormFixMask::GetInst()->SaveState(); }
372376
inline int FormFixMask_GetCPSize() { return FormFixMask::GetInst()->GetCPSize(); }
373377
inline bool FormFixMask_GetShowOnlySelectedStroke() { return FormFixMask::GetInst()->GetShowOnlySelectedStroke(); }
374378
inline int FormFixMask_GetMCScale() { return FormFixMask::GetInst()->GetMCScale(); }

RoiPainter4D/RoiPainter4D/Mode/ModeFixMask.cpp

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void ModeFixMask::StartMode()
7979
FormFixMask_InitAllItems();
8080
FormFixMask_Show();
8181
std::cout << "ModeFixMask...startMode DONE-----\n";
82+
std::cout << "Debug mode is available (Shift+Ctrl+F12).\n";
8283
}
8384

8485

@@ -311,42 +312,30 @@ void ModeFixMask::KeyDown(int nChar)
311312

312313
if (nChar == VK_F1)
313314
{
314-
// load state
315-
if (IsShiftKeyOn() && IsCtrKeyOn())
316-
{
317-
std::string fpath = "state.statelog";
318-
std::set<int> set_frame_idx;
319-
const int num_frames = ImageCore::GetInst()->GetNumFrames();
320-
for (int i = 0; i < num_frames; ++i)
321-
{
322-
set_frame_idx.insert(i);
323-
}
324-
325-
LoadState(fpath, set_frame_idx);
326-
}
315+
// show stroke matching
316+
const int frame_idx = formVisParam_getframeI();
317+
std::vector<int> fixed_verts_idxs;
318+
m_matched_pos = std::vector<Eigen::Vector3f>();
319+
std::vector<EVec3f> target_pos = std::vector<Eigen::Vector3f>();
320+
FindClosestPointFromStroke(frame_idx, fixed_verts_idxs, target_pos, m_matched_pos);
327321
}
328322
else if (nChar == VK_F2)
329323
{
330-
// save state
331-
if (IsShiftKeyOn() && IsCtrKeyOn())
324+
// deform all frame
325+
const int num_frames = ImageCore::GetInst()->GetNumFrames();
326+
for (int i = 0; i < num_frames; ++i)
332327
{
333-
std::string fpath = "state.statelog";
334-
std::set<int> set_frame_idx;
335-
const int num_frames = ImageCore::GetInst()->GetNumFrames();
336-
for (int i = 0; i < num_frames; ++i)
337-
{
338-
set_frame_idx.insert(i);
339-
}
340-
SaveState(fpath, set_frame_idx);
328+
Deform(i);
341329
}
342330
}
343331
else if (nChar == VK_F3)
344332
{
345-
// show stroke matching
346-
std::vector<int> fixed_verts_idxs;
347-
m_matched_pos = std::vector<Eigen::Vector3f>();
348-
std::vector<EVec3f> target_pos = std::vector<Eigen::Vector3f>();
349-
FindClosestPointFromStroke(fixed_verts_idxs, target_pos, m_matched_pos);
333+
// deform all frame
334+
const int num_frames = ImageCore::GetInst()->GetNumFrames();
335+
for (int i = 0; i < num_frames; ++i)
336+
{
337+
ReloadMesh(i);
338+
}
350339
}
351340
else if (nChar == VK_F4)
352341
{
@@ -392,9 +381,9 @@ void ModeFixMask::KeyDown(int nChar)
392381
std::cout << "debug mode: " << (debug ? "ON" : "OFF") << "\n";
393382
if (debug)
394383
{
395-
std::cout << "[F1] Load state (Shift+Ctrl+F1)" << "\n";
396-
std::cout << "[F2] Save state (Shift+Ctrl+F2)" << "\n";
397-
std::cout << "[F3] Show matching between strokes and mesh" << "\n";
384+
std::cout << "[F1] Show matching between strokes and mesh" << "\n";
385+
std::cout << "[F2] Deform mesh all frame" << "\n";
386+
std::cout << "[F3] Reload mesh all frame" << "\n";
398387
std::cout << "[F4] Share selected stroke" << "\n";
399388
std::cout << "[F5] Unshare selected stroke" << "\n";
400389
std::cout << "[F6] Lock selected stroke" << "\n";
@@ -466,7 +455,6 @@ void ModeFixMask::DrawScene(
466455
{
467456
m_strokes[frame_idx].DrawStrokes(m_show_only_selected_stroke);
468457

469-
#ifdef DEBUG_MODE_FIXMASK
470458
for (int i = 0; i < m_matched_pos.size(); ++i)
471459
{
472460
static const float COLOR_W[4] = { 1.0f, 1.0f, 1.0f, 0.5f };
@@ -482,7 +470,6 @@ void ModeFixMask::DrawScene(
482470
TMesh::DrawSphere(m_matched_pos[i], 0.3f);
483471
glDisable(GL_LIGHTING);
484472
}
485-
#endif
486473
}
487474

488475
// draw control points
@@ -497,16 +484,21 @@ void ModeFixMask::DrawScene(
497484
void ModeFixMask::Deform()
498485
{
499486
const int frame_idx = formVisParam_getframeI();
487+
Deform(frame_idx);
488+
}
500489

490+
491+
void ModeFixMask::Deform(const int _frame_idx)
492+
{
501493
if (!m_exist_mesh || !m_mask_mesh.is_initialized) return;
502494

503-
m_mask_mesh.GetMesh(frame_idx).Set(m_tmeshes[frame_idx]);
495+
m_mask_mesh.GetMesh(_frame_idx).Set(m_tmeshes[_frame_idx]);
504496

505497
std::vector<int> fixed_verts_idxs;
506498
std::vector<EVec3f> fixed_positions;
507499
std::vector<EVec3f> src_positions;
508500

509-
FindClosestPointFromStroke(fixed_verts_idxs, fixed_positions, src_positions);
501+
FindClosestPointFromStroke(_frame_idx, fixed_verts_idxs, fixed_positions, src_positions);
510502

511503
// Sort by index
512504
std::vector<std::pair<int, EVec3f>> indexPointPairs;
@@ -528,7 +520,7 @@ void ModeFixMask::Deform()
528520
if (fixed_verts_idxs.size() == 0) return;
529521

530522
// Deform
531-
m_laplacian_deformer[frame_idx].Deform(fixed_verts_idxs, fixed_positions);
523+
m_laplacian_deformer[_frame_idx].Deform(fixed_verts_idxs, fixed_positions);
532524

533525
formMain_RedrawMainPanel();
534526
formMain_ActivateMainForm();
@@ -647,7 +639,6 @@ void ModeFixMask::ConvertMeshToMask()
647639
void ModeFixMask::ReloadMesh()
648640
{
649641
const int frame_idx = formVisParam_getframeI();
650-
651642
ReloadMesh(frame_idx);
652643
}
653644

@@ -700,22 +691,20 @@ void ModeFixMask::SetShowOnlySelectedStroke()
700691

701692

702693

703-
void ModeFixMask::FindClosestPointFromStroke(std::vector<int>& _idxs, std::vector<EVec3f>& _target_pos, std::vector<EVec3f>& _src_pos)
694+
void ModeFixMask::FindClosestPointFromStroke(const int _frame_idx, std::vector<int>& _idxs, std::vector<EVec3f>& _target_pos, std::vector<EVec3f>& _src_pos)
704695
{
705-
const int frame_idx = formVisParam_getframeI();
706-
707696
if (!m_mask_mesh.is_initialized) return;
708697

709-
TMesh& mesh = m_mask_mesh.GetMesh(frame_idx);
698+
TMesh& mesh = m_mask_mesh.GetMesh(_frame_idx);
710699

711-
auto& strokes = m_strokes[frame_idx].GetStroke();
700+
auto& strokes = m_strokes[_frame_idx].GetStroke();
712701
const int num_stroke = strokes.size();
713702

714703
// for stroke
715704
for (int i = 0; i < num_stroke; ++i) {
716705
const auto stroke = strokes[i];
717706
const int num_p = stroke.size();
718-
const int commonXYZ = m_strokes[frame_idx].GetStrokeInst(i)->GetCommonXYZ();
707+
const int commonXYZ = m_strokes[_frame_idx].GetStrokeInst(i)->GetCommonXYZ();
719708
const EVec3f vec0 = EVec3f(
720709
commonXYZ == 0 ? 1.0f : 0.0f,
721710
commonXYZ == 1 ? 1.0f : 0.0f,

RoiPainter4D/RoiPainter4D/Mode/ModeFixMask.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class ModeFixMask :
8787
void DrawScene(const EVec3f& cuboid, const EVec3f& camP, const EVec3f& camF);
8888
// -----------------------------------------------------------------
8989
void Deform();
90+
void Deform(const int);
9091

9192
void Do();
9293
void Undo();
@@ -112,7 +113,7 @@ class ModeFixMask :
112113

113114

114115
private:
115-
void FindClosestPointFromStroke(std::vector<int>&, std::vector<EVec3f>&, std::vector<EVec3f>&);
116+
void FindClosestPointFromStroke(const int, std::vector<int>&, std::vector<EVec3f>&, std::vector<EVec3f>&);
116117

117118
//Add?
118119

RoiPainter4D/x64/Release/zlib1.dll

88.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)