]> Creatis software - creaMaracasVisu.git/commitdiff
#3494 Detect normals patch showNPoints_tool box
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Sat, 22 Oct 2022 01:53:41 +0000 (03:53 +0200)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Sat, 22 Oct 2022 01:53:41 +0000 (03:53 +0200)
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h

index 5b98808d6fdc87df40001d2546a046da84d1ebcf..02d1be882f3ab661f16eb2eacd4a8731079a88de 100644 (file)
@@ -36,7 +36,7 @@ void ShowNPoints_Tools::CreatePatch01()
          (wsp->GetModelShowNPoints()->GetLstPointsSize()==4) &&
          (bbGetInputMesh()!=NULL ) )
     {
-        std::vector<long int>   lstIdNormal;
+        std::vector<long int>   lstIdNormalSurface;
         double                  spc[3];
                                 spc[0]          = bbGetInputSpacing()[0];
                                 spc[1]          = bbGetInputSpacing()[1];
@@ -53,26 +53,41 @@ void ShowNPoints_Tools::CreatePatch01()
         std::vector<int> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
         std::vector<int> 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; i<size; i++)
                {
-                   nValue        = dataarray->GetTuple3( 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 {
index d3c1c9ea0be52c8a37e493ea5ff17d4b805ed8f3..95d6e9e5a8792f44166edd4f2ea34e55285bcf9e 100644 (file)
@@ -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];
 }
 
 //------------------------------------------------------------------------
index 580f07d7f4a5f53b4663341f6acd30d02f3d1c07..8963b7806940770cf7fdbd6d5cb124f4909d26af 100644 (file)
 
 
     #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<int> 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();
 }
 
index a9a646bf781f65074edb647c7a56232c9752cd5b..48f24353416bc0ffd29d82aa25b53fb37aa2af78 100644 (file)
@@ -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);