From 86497958247bb79fb78c28efa55c6851b6a2b6d7 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Sat, 22 Oct 2022 03:53:41 +0200 Subject: [PATCH] #3494 Detect normals patch showNPoints_tool box --- .../bbcreaMaracasVisuShowNPoints_Tools.cxx | 120 ++++++++++++++---- .../wxWindows/widgets/ModelShowNPoints.cxx | 6 +- .../wxWindows/widgets/WidgetShowNPoints.cxx | 29 ++++- .../wxWindows/widgets/WidgetShowNPoints.h | 1 + 4 files changed, 128 insertions(+), 28 deletions(-) diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx index 5b98808..02d1be8 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx @@ -36,7 +36,7 @@ void ShowNPoints_Tools::CreatePatch01() (wsp->GetModelShowNPoints()->GetLstPointsSize()==4) && (bbGetInputMesh()!=NULL ) ) { - std::vector lstIdNormal; + std::vector lstIdNormalSurface; double spc[3]; spc[0] = bbGetInputSpacing()[0]; spc[1] = bbGetInputSpacing()[1]; @@ -53,26 +53,41 @@ void ShowNPoints_Tools::CreatePatch01() std::vector lstY = wsp->GetModelShowNPoints()->GetLstPointsY(); std::vector lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ(); + wsp->ErasePoint( 0 ); + wsp->ErasePoint( 0 ); + wsp->ErasePoint( 0 ); + wsp->ErasePoint( 0 ); + // --- Group 0 --- - wsp->ErasePoint( 2 ); - wsp->ErasePoint( 2 ); dx = lstX[1]-lstX[0]; dy = lstY[1]-lstY[0]; dz = lstZ[1]-lstZ[0]; - s=0.33333; + s = 0; p[0] = lstX[0] + dx*s; p[1] = lstY[0] + dy*s; p[2] = lstZ[0] + dz*s; NearestPointToMesh(points, pointLocator, spc, p,pM); wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) ); - s=s*2; + lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) ); + s = 0.33333; + p[0] = lstX[0] + dx*s; + p[1] = lstY[0] + dy*s; + p[2] = lstZ[0] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + s = 0.6666666; + p[0] = lstX[0] + dx*s; + p[1] = lstY[0] + dy*s; + p[2] = lstZ[0] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0],pM[1], pM[2],""); + s = 1; p[0] = lstX[0] + dx*s; p[1] = lstY[0] + dy*s; p[2] = lstZ[0] + dz*s; NearestPointToMesh(points, pointLocator, spc, p,pM); wsp->InsertPoint(pM[0],pM[1], pM[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) ); + lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) ); // --- Group 1 --- wsp->InsertCollectionAfter_(); @@ -81,13 +96,11 @@ void ShowNPoints_Tools::CreatePatch01() p[2] = (lstZ[0]+lstZ[3])/2; NearestPointToMesh(points, pointLocator, spc, p,pM); wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) ); p[0] = (lstX[1]+lstX[2])/2; p[1] = (lstY[1]+lstY[2])/2; p[2] = (lstZ[1]+lstZ[2])/2; NearestPointToMesh(points, pointLocator, spc, p,pM); wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(pM) ); p[0] = (lstX[0]+lstX[1]+lstX[2]+lstX[3])/4; p[1] = (lstY[0]+lstY[1]+lstY[2]+lstY[3])/4; p[2] = (lstZ[0]+lstZ[1]+lstZ[2]+lstZ[3])/4; wsp->InsertPoint(p[0] ,p[1], p[2],""); @@ -96,13 +109,15 @@ void ShowNPoints_Tools::CreatePatch01() p[0] = lstX[3]; p[1] = lstY[3]; p[2] = lstZ[3]; - wsp->InsertPoint(p[0] ,p[1], p[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(p) ); + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(p) ); p[0] = lstX[2]; p[1] = lstY[2]; p[2] = lstZ[2]; - wsp->InsertPoint(p[0] ,p[1], p[2],""); - lstIdNormal.push_back( pointLocator->FindClosestPoint(p) ); + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(p) ); dx = lstX[2]-lstX[3]; dy = lstY[2]-lstY[3]; dz = lstZ[2]-lstZ[3]; @@ -119,8 +134,8 @@ void ShowNPoints_Tools::CreatePatch01() NearestPointToMesh(points, pointLocator, spc, p,pM); wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); - wsp->SetOutputBox(); - pointLocator->Delete(); + wsp->SetOutputBox(); + pointLocator->Delete(); // Check normals @@ -129,16 +144,16 @@ void ShowNPoints_Tools::CreatePatch01() double n1[3]; vtkPointData *pointdata = bbGetInputMesh()->GetPointData(); vtkDataArray *dataarray = pointdata->GetNormals(); - int i,size = lstIdNormal.size(); + int i,size = lstIdNormalSurface.size(); n1[0]=0; n1[1]=0; n1[2]=0; for (i=0; iGetTuple3( i ); - n1[0] = n1[0]+nValue[0]; - n1[1] = n1[1]+nValue[1]; - n1[2] = n1[2]+nValue[2]; + nValue = dataarray->GetTuple3( lstIdNormalSurface[i] ); + n1[0] = n1[0] + nValue[0]; + n1[1] = n1[1] + nValue[1]; + n1[2] = n1[2] + nValue[2]; } // for i n1[0] = n1[0]/size; n1[1] = n1[1]/size; @@ -146,10 +161,71 @@ void ShowNPoints_Tools::CreatePatch01() // 2. Calcular el promedio de 4 normales de la nueva superficie -> V2 -// 3. Calcular el angulo entre V1 y V2 -// 4. Si el angulo es major de 90 Invertir las normales de la superficie actual + double pC[3]; + double pM1[3]; + double pM2[3]; + double n2[3]; + n2[0] = 0; + n2[1] = 0; + n2[2] = 0; + // Collection 0 with 4 points + // Collection 1 with 3 points + // Collection 2 with 4 points + wsp->GetCollectionPoint(1,1, pC); + wsp->GetCollectionPoint(0,0, pM); + vtkMath::Subtract(pM,pC,pM1); + wsp->GetCollectionPoint(0,3, pM); + vtkMath::Subtract(pM,pC,pM2); + vtkMath::Cross(pM1,pM2,pM); + n2[0] = pM[0]; + n2[1] = pM[1]; + n2[2] = pM[2]; + + wsp->GetCollectionPoint(0,3, pM); + vtkMath::Subtract(pM,pC,pM1); + wsp->GetCollectionPoint(2,3, pM); + vtkMath::Subtract(pM,pC,pM2); + vtkMath::Cross(pM1,pM2,pM); + n2[0] = n2[0] + pM[0]; + n2[1] = n2[1] + pM[1]; + n2[2] = n2[2] + pM[2]; + + wsp->GetCollectionPoint(2,3, pM); + vtkMath::Subtract(pM,pC,pM1); + wsp->GetCollectionPoint(2,0, pM); + vtkMath::Subtract(pM,pC,pM2); + vtkMath::Cross(pM1,pM2,pM); + n2[0] = n2[0] + pM[0]; + n2[1] = n2[1] + pM[1]; + n2[2] = n2[2] + pM[2]; + + wsp->GetCollectionPoint(2,0, pM); + vtkMath::Subtract(pM,pC,pM1); + wsp->GetCollectionPoint(0,0, pM); + vtkMath::Subtract(pM,pC,pM2); + vtkMath::Cross(pM1,pM2,pM); + n2[0] = n2[0] + pM[0]; + n2[1] = n2[1] + pM[1]; + n2[2] = n2[2] + pM[2]; + + n2[0] = n2[0] / 4; + n2[1] = n2[1] / 4; + n2[2] = n2[2] / 4; + + +// 3. Calcular el angulo entre V1 y V2 + double angle = vtkMath::AngleBetweenVectors(n1,n2) * 180 / vtkMath::Pi(); + + printf("EED ShowNPoints_Tools::CreatePatch01 n1 %f %f %f\n", n1[0] , n1[1] , n1[2] ); + printf("EED ShowNPoints_Tools::CreatePatch01 n2 %f %f %f\n", n2[0] , n2[1] , n2[2] ); + printf("EED ShowNPoints_Tools::CreatePatch01 angle %f\n", angle); + // 4. Si el angulo es major de 90 Invertir las normales de la superficie actual + if (angle>90) + { + wsp->InvertLstPoints_(); + } // if angle // --- Finish --- wsp->UndoRedo_SaveCollection(); } else { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx index d3c1c9e..95d6e9e 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx @@ -97,9 +97,9 @@ std::string ModelShowNPoints::CleanSpaces(std::string ss) //------------------------------------------------------------------------ void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z) { - *x=lstPointsX[id]; - *y=lstPointsY[id]; - *z=lstPointsZ[id]; + *x = lstPointsX[id]; + *y = lstPointsY[id]; + *z = lstPointsZ[id]; } //------------------------------------------------------------------------ diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx index 580f07d..8963b78 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx @@ -41,13 +41,15 @@ #if defined(MACOSX) - UndoRedoDir = "/tmp"; + UndoRedoDir = "/tmp/creatools"; #else // Linux - UndoRedoDir = "/tmp"; + UndoRedoDir = "/tmp/creatools"; #endif printf("WidgetShowNPoints::WidgetShowNPoints UndoRedoDir = %s %p \n", UndoRedoDir.c_str() , this ); - // Erasing files of more than 1 day old ( +1 ) + std::string cmd1 = "mkdir "+ UndoRedoDir; + system( cmd1.c_str() ); + // Erasing files of more than 1 day old ( +1 ) std::string cmd= "find "+UndoRedoDir+" -name \"UndoRedo_collection_*.undoredo\" -type f -mtime +1 -delete"; system( cmd.c_str() ); @@ -1294,6 +1296,15 @@ void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event) } // dialog box } +//------------------------------------------------------------------------ +void WidgetShowNPoints::GetCollectionPoint(int idCol,int idPoint, double *pPoint) +{ + int x,y,z; + lstModelShowNPoints[idCol]->GetIdPoint(idPoint,&x,&y,&z); + pPoint[0] = x; + pPoint[1] = y; + pPoint[2] = z; +} //------------------------------------------------------------------------ std::vector WidgetShowNPoints::GetLstPointsX() @@ -1415,10 +1426,22 @@ int WidgetShowNPoints::GetLstModelShowNPointsSize() void WidgetShowNPoints::InvertLstPoints_() { int i,size=lstModelShowNPoints.size(); + for (i=0 ; i < size ; i++) { lstModelShowNPoints[i]->InversLstPoints(); } // for iM + + /* + ModelShowNPoints* tmpModel; + int size2=size/2; + for (i=0 ; i < size2 ; i++) + { + tmpModel = lstModelShowNPoints[i]; + lstModelShowNPoints[i] = lstModelShowNPoints[size-1-i]; + lstModelShowNPoints[size-1-i] = tmpModel; + } // for iM + */ SetOutputBox(); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h index a9a646b..48f2435 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h @@ -62,6 +62,7 @@ class WidgetShowNPoints : public wxPanel void ResetCollections_(); void OnResetCollections_(); void OnResetCollections(wxCommandEvent &event); + void GetCollectionPoint(int idCol,int idPoint, double *pPoint); void OnUndo(wxCommandEvent &event); void OnRedo(wxCommandEvent &event); -- 2.47.1