]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx
#3485 ShowNPionts for Multiple Groups
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuShowNPoints_Tools.cxx
index 5f16750f664b285cdf66bce33b89b642fa9a3a75..01ab191170908674bbabc1b465400e7a4dded003 100644 (file)
 //===== 
 #include "bbcreaMaracasVisuShowNPoints_Tools.h"
 #include "bbcreaMaracasVisuPackage.h"
+
+
 namespace bbcreaMaracasVisu
 {
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints_Tools)
 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints_Tools,bbtk::AtomicBlackBox);
 
+
+
+void ShowNPoints_Tools::NearestPointToMesh( vtkPoints *points,vtkStaticPointLocator *pointLocator,double *spc,double *p,double *pM)
+{
+    
+    p[0] = p[0] * spc[0];
+    p[1] = p[1] * spc[1];
+    p[2] = p[2] * spc[2];
+    points->GetPoint( pointLocator->FindClosestPoint(p) , pM );
+    pM[0] = pM[0] / spc[0];
+    pM[1] = pM[1] / spc[1];
+    pM[2] = pM[2] / spc[2];
+}
+
 void ShowNPoints_Tools::CreatePatch01()
 {
-    bbGetInputWidgetShowNPoints()->CreatePatch01(  );
+    WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
+    if ( (wsp->GetLstModelShowNPointsSize()==1) &&
+         (wsp->GetModelShowNPoints()->GetLstPointsSize()==4) &&
+         (bbGetInputMesh()!=NULL ) )
+    {
+        double                  spc[3];
+                                spc[0]          = bbGetInputSpacing()[0];
+                                spc[1]          = bbGetInputSpacing()[1];
+                                spc[2]          = bbGetInputSpacing()[2];
+        vtkPoints               *points         = bbGetInputMesh()->GetPoints();
+        vtkStaticPointLocator   *pointLocator   = vtkStaticPointLocator::New();
+        pointLocator->SetDataSet( bbGetInputMesh() );
+        pointLocator->BuildLocator();
+
+        wsp->StopTrackPoint();
+        double p[3],pM[3];
+        double dx,dy,dz,s;
+        std::vector<int> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
+        std::vector<int> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
+        std::vector<int> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
+        
+        // --- 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;
+        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=s*2;
+        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],"");
+
+        // --- Group 1 ---
+        wsp->OnInsertCollectionAfter_();
+          p[0] = (lstX[0]+lstX[3])/2;
+          p[1] = (lstY[0]+lstY[3])/2;
+          p[2] = (lstZ[0]+lstZ[3])/2;
+          NearestPointToMesh(points, pointLocator, spc, p,pM);
+          wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+          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],"");
+          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],"");
+
+        // --- Group 2 ---
+        wsp->OnInsertCollectionAfter_();
+          p[0] = lstX[3];
+          p[1] = lstY[3];
+          p[2] = lstZ[3];
+          wsp->InsertPoint(p[0] ,p[1], p[2],"");
+          p[0] = lstX[2];
+          p[1] = lstY[2];
+          p[2] = lstZ[2];
+          wsp->InsertPoint(p[0] ,p[1], p[2],"");
+          dx = lstX[2]-lstX[3];
+          dy = lstY[2]-lstY[3];
+          dz = lstZ[2]-lstZ[3];
+          s=0.33333;
+          p[0] = lstX[3] + dx*s;
+          p[1] = lstY[3] + dy*s;
+          p[2] = lstZ[3] + dz*s;
+          NearestPointToMesh(points, pointLocator, spc, p,pM);
+          wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+          s=s*2;
+          p[0] = lstX[3] + dx*s;
+          p[1] = lstY[3] + dy*s;
+          p[2] = lstZ[3] + dz*s;
+          NearestPointToMesh(points, pointLocator, spc, p,pM);
+          wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
+
+        wsp->SetOutputBox();
+        pointLocator->Delete();
+    } else {
+            printf("EED ShowNPoints_Tools::CreatePatch01  Warning patch not apply. Need juste one group with four points\n");
+    } // if
 }
 
+
+
 //=====
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
@@ -80,6 +183,12 @@ void ShowNPoints_Tools::bbUserSetDefaultValues()
    bbSetInputType(0);
    bbSetInputMesh(NULL);
    bbSetInputWidgetShowNPoints(NULL);
+    
+    std::vector<double> spc;
+    spc.push_back(1);
+    spc.push_back(1);
+    spc.push_back(1);
+    bbSetInputSpacing(spc);
 }
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)