2 // 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)
4 #include "bbcreaMaracasVisuShowNPoints_Tools.h"
5 #include "bbcreaMaracasVisuPackage.h"
7 #include <vtkPointData.h>
8 #include <vtkDataArray.h>
12 namespace bbcreaMaracasVisu
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints_Tools)
16 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints_Tools,bbtk::AtomicBlackBox);
20 void ShowNPoints_Tools::NearestPointToMesh( vtkPoints *points,vtkStaticPointLocator *pointLocator,double *spc,double *p,double *pM)
25 points->GetPoint( pointLocator->FindClosestPoint(p) , pM );
26 pM[0] = pM[0] / spc[0];
27 pM[1] = pM[1] / spc[1];
28 pM[2] = pM[2] / spc[2];
31 void ShowNPoints_Tools::CreatePatch_3points()
33 //printf("PG ShowNPoints_Tools::CreatePatch_3points Entered patch 3 points !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
34 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
36 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
37 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
38 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
55 vtkMath::Subtract(pC,pA,v);
56 vtkMath::Subtract(pB,pA,u);
58 /**point in AC closest to B.
59 *formula t=(V)dot(U)/(V)dot(V)
61 double t = vtkMath::Dot(v,u)/vtkMath::Dot(v,v);
63 *formula A+t(C-A) -> A+tV
65 vtkMath::MultiplyScalar(v, t);
67 vtkMath::Add(pA, v, nP);
69 //calculate direction vector from found point to B
71 vtkMath::Subtract(pB, nP, dirVector);
76 //Add and subtract direction vector to A and C to find the 4 points to create the patch,
78 std::vector<double> resListX;
79 std::vector<double> resListY;
80 std::vector<double> resListZ;
82 vtkMath::Add(pA, dirVector, pointAdd);
83 vtkMath::Subtract(pA, dirVector, pointSub);
85 resListX.push_back(pointSub[0]);
86 resListY.push_back(pointSub[1]);
87 resListZ.push_back(pointSub[2]);
89 resListX.push_back(pointAdd[0]);
90 resListY.push_back(pointAdd[1]);
91 resListZ.push_back(pointAdd[2]);
94 vtkMath::Add(pC, dirVector, pointAdd);
95 vtkMath::Subtract(pC, dirVector, pointSub);
97 resListX.push_back(pointAdd[0]);
98 resListY.push_back(pointAdd[1]);
99 resListZ.push_back(pointAdd[2]);
101 resListX.push_back(pointSub[0]);
102 resListY.push_back(pointSub[1]);
103 resListZ.push_back(pointSub[2]);
105 //Create patch given the previously calculated points (4 points)
106 CreatePatch_Points(resListX, resListY, resListZ);
109 void ShowNPoints_Tools::CreatePatch_4points()
111 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
113 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
114 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
115 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
116 CreatePatch_Points(lstX, lstY, lstZ);
119 void ShowNPoints_Tools::InitCreatePatch_Points()
121 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
122 wsp->StopAutoAddPoints();
123 wsp->StopTrackPoint();
124 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ))
126 if(wsp->GetModelShowNPoints()->GetLstPointsSize()==4){
127 CreatePatch_4points();
129 else if(wsp->GetModelShowNPoints()->GetLstPointsSize()==3){
130 CreatePatch_3points();
133 printf("PG ShowNPoints_Tools::CreatePatch_Npoints Warning patch not apply. Number of points is invalid. Group should have 3 or 4 points\n");
137 printf("PG ShowNPoints_Tools::CreatePatch_Npoints Warning patch not apply. groups or mesh invalid. Need 1 group of 3 or 4 points, and a mesh\n");
141 wsp->RefreshCollectionText();
142 wsp->RefreshColourCollection();
144 wsp->UndoRedo_SaveCollection();
148 void ShowNPoints_Tools::InitCreateVolumeSurface_Points()
150 InitCreatePatch_Points(); // 1 group -> 3 groups
152 // 3 groups to 4 groups
153 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
154 wsp->StopAutoAddPoints();
155 wsp->StopTrackPoint();
156 if( wsp->GetLstModelShowNPointsSize()==3 )
159 double pC1[3]; // fist point
161 double pC2A[3]; // first middle point
162 double pC2B[3]; // second midle point
163 double pC3[3]; // last point
164 double pN[3]; // new over the surface
166 vtkPoints *points = bbGetInputMesh()->GetPoints();
167 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
168 pointLocator->SetDataSet( bbGetInputMesh() );
169 pointLocator->BuildLocator();
170 spc[0] = bbGetInputSpacing()[0];
171 spc[1] = bbGetInputSpacing()[1];
172 spc[2] = bbGetInputSpacing()[2];
173 wsp->InsertCollectionAfter_();
174 wsp->GetCollectionPoint(1,0, pC1);
175 wsp->GetCollectionPoint(1,2, pC3);
179 pC2A[0]=pC1[0]+dx*0.33333; pC2A[1]=pC1[1]+dy*0.3333; pC2A[2]=pC1[2]+dz*0.33333;
180 pC2B[0]=pC1[0]+dx*0.66666; pC2B[1]=pC1[1]+dy*0.6666; pC2B[2]=pC1[2]+dz*0.66666;
182 wsp->InsertPoint(pC1[0] ,pC1[1], pC1[2],"");
184 NearestPointToMesh(points, pointLocator, spc, pC2A,pN);
185 wsp->InsertPoint(pN[0] ,pN[1], pN[2],"");
187 NearestPointToMesh(points, pointLocator, spc, pC2B,pN);
188 wsp->InsertPoint(pN[0] ,pN[1], pN[2],"");
190 wsp->InsertPoint(pC3[0] ,pC3[1], pC3[2],"");
192 // Add points to the other Groups
193 std::vector<double> pointStart;
194 pointStart.push_back( pC1[0] );
195 pointStart.push_back( pC1[1] );
196 pointStart.push_back( pC1[2] );
197 std::vector<double> pointEnd;
198 pointEnd.push_back( pC3[0] );
199 pointEnd.push_back( pC3[1] );
200 pointEnd.push_back( pC3[2] );
202 wsp->SetActualCollection(0);
203 wsp->SetReferencePoint(pointStart);
204 wsp->OnInsertPoint_();
205 wsp->SetReferencePoint(pointEnd);
206 wsp->OnInsertPoint_();
208 wsp->SetActualCollection(2);
209 wsp->SetReferencePoint(pointStart);
210 wsp->OnInsertPoint_();
211 wsp->SetReferencePoint(pointEnd);
212 wsp->OnInsertPoint_();
215 wsp->RefreshCollectionText();
216 wsp->RefreshColourCollection();
218 wsp->UndoRedo_SaveCollection();
220 pointLocator->Delete();
226 void ShowNPoints_Tools::CreatePatch_Points(std::vector<double> lstX, std::vector<double> lstY, std::vector<double> lstZ)
228 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
229 std::vector<long int> lstIdNormalSurface;
231 spc[0] = bbGetInputSpacing()[0];
232 spc[1] = bbGetInputSpacing()[1];
233 spc[2] = bbGetInputSpacing()[2];
234 vtkPoints *points = bbGetInputMesh()->GetPoints();
235 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
236 pointLocator->SetDataSet( bbGetInputMesh() );
237 pointLocator->BuildLocator();
238 wsp->StopTrackPoint();
242 wsp->DeleteAllPoints_();
243 //wsp->ErasePoint( 0 );
244 //wsp->ErasePoint( 0 );
245 //wsp->ErasePoint( 0 );
246 //wsp->ErasePoint( 0 );
248 dx = lstX[1]-lstX[0];
249 dy = lstY[1]-lstY[0];
250 dz = lstZ[1]-lstZ[0];
254 for(int sect = 0; sect < 5; sect++)
256 p[0] = lstX[0] + dx*(sect*part);
257 p[1] = lstY[0] + dy*(sect*part);
258 p[2] = lstZ[0] + dz*(sect*part);
260 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
261 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
262 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
265 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
266 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
267 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
269 NearestPointToMesh(points, pointLocator, spc, p,pM);
270 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
271 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
275 //EED double centroid[3];
277 wsp->InsertCollectionAfter_();
278 p[0] = (lstX[0]+lstX[3])/2;
279 p[1] = (lstY[0]+lstY[3])/2;
280 p[2] = (lstZ[0]+lstZ[3])/2;
281 NearestPointToMesh(points, pointLocator, spc, p,pM);
282 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
283 p[0] = (lstX[1]+lstX[2])/2;
284 p[1] = (lstY[1]+lstY[2])/2;
285 p[2] = (lstZ[1]+lstZ[2])/2;
286 NearestPointToMesh(points, pointLocator, spc, p,pM);
287 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
288 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;
289 wsp->InsertPoint(p[0] ,p[1], p[2],"");
290 //EED std::copy(std::begin(p), std::end(p), std::begin(centroid));
292 wsp->InsertCollectionAfter_();
293 dx = lstX[2]-lstX[3];
294 dy = lstY[2]-lstY[3];
295 dz = lstZ[2]-lstZ[3];
296 for(int sect = 0; sect < 5; sect++)
298 p[0] = lstX[3] + dx*(sect*part);
299 p[1] = lstY[3] + dy*(sect*part);
300 p[2] = lstZ[3] + dz*(sect*part);
302 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
303 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
304 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
307 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
308 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
309 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
311 NearestPointToMesh(points, pointLocator, spc, p,pM);
312 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
313 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
315 pointLocator->Delete();
317 // 1. Recorrer las normales de lstIdNormals y calcular el promedio -> V1
320 vtkPointData *pointdata = bbGetInputMesh()->GetPointData();
321 vtkDataArray *dataarray = pointdata->GetNormals();
322 int i,size = lstIdNormalSurface.size();
326 for (i=0; i<size; i++)
328 nValue = dataarray->GetTuple3( lstIdNormalSurface[i] );
329 n1[0] = n1[0] + nValue[0];
330 n1[1] = n1[1] + nValue[1];
331 n1[2] = n1[2] + nValue[2];
337 // 2. Calcular el promedio de 4 normales de la nueva superficie -> V2
345 // Collection 0 with 4 points
346 // Collection 1 with 3 points
347 // Collection 2 with 4 points
348 wsp->GetCollectionPoint(1,1, pC);
350 wsp->GetCollectionPoint(0,0, pM);
351 vtkMath::Subtract(pM,pC,pM1);
352 wsp->GetCollectionPoint(0,3, pM);
353 vtkMath::Subtract(pM,pC,pM2);
354 vtkMath::Cross(pM1,pM2,pM);
359 wsp->GetCollectionPoint(0,3, pM);
360 vtkMath::Subtract(pM,pC,pM1);
361 wsp->GetCollectionPoint(2,3, pM);
362 vtkMath::Subtract(pM,pC,pM2);
363 vtkMath::Cross(pM1,pM2,pM);
364 n2[0] = n2[0] + pM[0];
365 n2[1] = n2[1] + pM[1];
366 n2[2] = n2[2] + pM[2];
368 wsp->GetCollectionPoint(2,3, pM);
369 vtkMath::Subtract(pM,pC,pM1);
370 wsp->GetCollectionPoint(2,0, pM);
371 vtkMath::Subtract(pM,pC,pM2);
372 vtkMath::Cross(pM1,pM2,pM);
373 n2[0] = n2[0] + pM[0];
374 n2[1] = n2[1] + pM[1];
375 n2[2] = n2[2] + pM[2];
377 wsp->GetCollectionPoint(2,0, pM);
378 vtkMath::Subtract(pM,pC,pM1);
379 wsp->GetCollectionPoint(0,0, pM);
380 vtkMath::Subtract(pM,pC,pM2);
381 vtkMath::Cross(pM1,pM2,pM);
382 n2[0] = n2[0] + pM[0];
383 n2[1] = n2[1] + pM[1];
384 n2[2] = n2[2] + pM[2];
390 // 3. Calcular el angulo entre V1 y V2
391 double angle = vtkMath::AngleBetweenVectors(n1,n2) * 180 / vtkMath::Pi();
392 // 4. Si el angulo es major de 90 Invertir las normales de la superficie actual
395 vtkMath::MultiplyScalar(n2, -1);
396 wsp->InvertLstPoints_();
400 //EED std::vector<double> normalOut(n2, n2 + 3);
401 //EED double norm = vtkMath::Norm(n2);
402 //EED normalOut[0] = normalOut[0]/norm;
403 //EED normalOut[1] = normalOut[1]/norm;
404 //EED normalOut[2] = normalOut[2]/norm;
406 //EED std::vector<double> outputData;
407 //EED outputData.insert(outputData.end(), ¢roid[0], ¢roid[3]);
408 //EED outputData.insert(outputData.end(), &normalOut[0], &normalOut[3]);
410 //EED bbSetOutputOut(outputData);
411 //bbSetOutputOut(normalOut);
415 wsp->UndoRedo_SaveCollection();
418 void ShowNPoints_Tools::MovePatchCenter()
422 std::vector<double> params = bbGetInputParams();
423 if(params.size() == 4)
425 if(params[3] != 1 && params[3] != -1)
427 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. direction of movement should be 1 or -1\n");
431 double centerPoint[3];
432 std::vector<double> normal, modPoint;
433 normal.push_back(params[0]);
434 normal.push_back(params[1]);
435 normal.push_back(params[2]);
436 int direction = -1 * params[3];
437 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
438 wsp->GetCollectionPoint(1,1, centerPoint);
439 modPoint.push_back(centerPoint[0] + direction * normal[0]);
440 modPoint.push_back(centerPoint[1] + direction * normal[1]);
441 modPoint.push_back(centerPoint[2] + direction * normal[2]);
442 wsp->SetCollectionPoint(1, 1, modPoint);
447 wsp->UndoRedo_SaveCollection();
449 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. Need 4: normal x y z and direction of movement (1 or -1)\n");
454 double step = bbGetInputParams()[0];
455 WidgetShowNPoints *wsp = bbGetInputWidgetShowNPoints();
456 wsp->SetActualCollection( wsp->GetLstModelShowNPointsSize()/2 );
457 ModelShowNPoints *modelSNP = wsp->GetModelShowNPoints( );
458 modelSNP->SetIdCurrentPoint( modelSNP->GetLstPointsSize()/2 );
459 wsp->MovePoint_( step );
463 * Creates a cutting surface with 1 group of points. This surface can have its area adjusted
464 * (increase or decrease the distance from the points to the center)
465 * The centroid is set as the output, to be used by the expanding tool.
467 void ShowNPoints_Tools::CreateExpandedSurface()
470 //Set Input to 0 as this function should only be executed manually but still update its children.
474 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
475 wsp->StopAutoAddPoints();
476 wsp->StopTrackPoint();
477 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
479 //Set Input to 0 as this function should only be executed manually but still update its children.
482 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
483 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
484 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
486 wsp->DeleteAllPoints_();
489 for(int i = 0; i < (int)lstX.size(); i++){
490 centroid[0] += lstX[i];
491 centroid[1] += lstY[i];
492 centroid[2] += lstZ[i];
494 centroid[0] /= lstX.size();
495 centroid[1] /= lstX.size();
496 centroid[2] /= lstX.size();
501 for(int i = 0; i < (int)lstX.size(); i++){
502 dV[0] = lstX[i] - centroid[0];
503 dV[1] = lstY[i] - centroid[1];
504 dV[2] = lstZ[i] - centroid[2];
505 vtkMath::Normalize(dV);
507 p[0] = lstX[i] + 4*dV[0];
508 p[1] = lstY[i] + 4*dV[1];
509 p[2] = lstZ[i] + 4*dV[2];
510 wsp->AddPoint(p[0] ,p[1], p[2],"");
512 std::vector<double> outData = {centroid[0], centroid[1], centroid[2]};
513 bbSetOutputOut(outData);
516 printf("PG ShowNPoints_Tools::CreateExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
520 wsp->UndoRedo_SaveCollection();
524 * Creates a cutting surface with 3 groups of points. This surface can have its area adjusted
525 * (Increase or decrease distance from points to centroid of spline or distance between splines)
526 * The centroid and normal is set as the Output, to be used by the expanding tools.
528 void ShowNPoints_Tools::CreateWideExpandedSurface()
531 //Set Input to 0 as this function is only used by the popup menu
535 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
536 wsp->StopAutoAddPoints();
537 wsp->StopTrackPoint();
539 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
541 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
542 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
543 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
545 wsp->DeleteAllPoints_();
550 for(int i = 0; i < (int)lstX.size(); i++){
551 centroid[0] += lstX[i];
552 centroid[1] += lstY[i];
553 centroid[2] += lstZ[i];
555 centroid[0] /= lstX.size();
556 centroid[1] /= lstX.size();
557 centroid[2] /= lstX.size();
560 double currNormal[3];
562 for(int i = 0; i < ((int)lstX.size())-1; i++){
563 v1[0] = lstX[i] - centroid[0];
564 v1[1] = lstY[i] - centroid[1];
565 v1[2] = lstZ[i] - centroid[2];
566 v2[0] = lstX[i+1] - centroid[0];
567 v2[1] = lstY[i+1] - centroid[1];
568 v2[2] = lstZ[i+1] - centroid[2];
569 vtkMath::Cross(v1, v2, currNormal);
570 normal[0] += currNormal[0];
571 normal[1] += currNormal[1];
572 normal[2] += currNormal[2];
575 normal[0] /= (lstX.size()-1);
576 normal[1] /= (lstX.size()-1);
577 normal[2] /= (lstX.size()-1);
579 vtkMath::Normalize(normal);
583 //Add new groups on both sides from the original spline
584 for(int group = 0; group < 2; group++){
585 for(int i = 0; i < (int) lstX.size(); i++){
586 dV[0] = lstX[i] - centroid[0];
587 dV[1] = lstY[i] - centroid[1];
588 dV[2] = lstZ[i] - centroid[2];
589 vtkMath::Normalize(dV);
591 np[0] = lstX[i] + dV[0]*4 + ((normal[0]*2)*addNormal);
592 np[1] = lstY[i] + dV[1]*4 + ((normal[1]*2)*addNormal);
593 np[2] = lstZ[i] + dV[2]*4 + ((normal[2]*2)*addNormal);
594 wsp->AddPoint(np[0] ,np[1], np[2],"");
597 if(group < 1)wsp->InsertCollectionAfter_();
600 std::vector<double> outData = {centroid[0], centroid[1], centroid[2], normal[0], normal[1], normal[2]};
601 bbSetOutputOut(outData);
605 wsp->UndoRedo_SaveCollection();
608 printf("PG ShowNPoints_Tools::CreateWideExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
613 * Given a cutting surface, expand its area by moving the points outwards of the main centroid.
615 void ShowNPoints_Tools::ExpandSurfaceArea()
617 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
618 wsp->StopAutoAddPoints();
619 wsp->StopTrackPoint();
621 if((wsp->GetLstModelShowNPointsSize()==1 || wsp->GetLstModelShowNPointsSize() == 2)
622 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
623 && (bbGetInputParams().size() == 4))
625 std::vector<double> params = bbGetInputParams();
626 double direction = params[3];
627 double centroid[3] = {params[0], params[1], params[2]};
629 double dV[3], currPoint[3], mdfdPoint[3];
631 std::vector<double> modPoint;
632 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
633 for(int i = 0; i < pointsPerSpline; i++){
634 wsp->GetCollectionPoint(0, i, currPoint);
635 dV[0] = currPoint[0] - centroid[0];
636 dV[1] = currPoint[1] - centroid[1];
637 dV[2] = currPoint[2] - centroid[2];
638 vtkMath::Normalize(dV);
640 vtkMath::MultiplyScalar(dV, direction);
641 vtkMath::Add(currPoint, dV, mdfdPoint);
642 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
643 wsp->SetCollectionPoint(0, i, modPoint);
645 if(wsp->GetLstModelShowNPointsSize() == 2){
646 wsp->GetCollectionPoint(1, i, currPoint);
647 vtkMath::Add(currPoint, dV, mdfdPoint);
648 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
649 wsp->SetCollectionPoint(1, i, modPoint);
654 printf("PG ShowNPoints_Tools::ExpandSurface Warning surface not apply. groups, points or params invalid. need 1 group of points, need 4 params(centroid and direction)\n");
658 wsp->UndoRedo_SaveCollection();
661 void ShowNPoints_Tools::ExpandPatch()
663 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
664 wsp->StopAutoAddPoints();
665 wsp->StopTrackPoint();
666 if((wsp->GetLstModelShowNPointsSize() == 3)
667 && (wsp->GetLstPointsX().size() == 13)
668 && (bbGetInputParams().size() == 4))
670 std::vector<double> params = bbGetInputParams();
671 double direction = params[3];
672 double centroid[3] = {params[0], params[1], params[2]};
674 std::vector<double> modPoint(3);
675 double currentPoint[3], dV[3], mdfdPoint[3];
676 for(int group = 0; group < 3; group++){
678 wsp->GetCollectionPoint(group, 0, currentPoint);
679 dV[0] = currentPoint[0] - centroid[0];
680 dV[1] = currentPoint[1] - centroid[1];
681 dV[2] = currentPoint[2] - centroid[2];
682 vtkMath::Normalize(dV);
683 vtkMath::MultiplyScalar(dV, direction);
684 vtkMath::Add(currentPoint, dV, mdfdPoint);
685 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
686 wsp->SetCollectionPoint(group, 0, modPoint);
687 wsp->GetCollectionPoint(group, 2, currentPoint);
688 dV[0] = currentPoint[0] - centroid[0];
689 dV[1] = currentPoint[1] - centroid[1];
690 dV[2] = currentPoint[2] - centroid[2];
691 vtkMath::Normalize(dV);
692 vtkMath::MultiplyScalar(dV, direction);
693 vtkMath::Add(currentPoint, dV, mdfdPoint);
694 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
695 wsp->SetCollectionPoint(group, 2, modPoint);
697 for(int i = 0; i < 5; i++){
698 wsp->GetCollectionPoint(group,i, currentPoint);
699 dV[0] = currentPoint[0] - centroid[0];
700 dV[1] = currentPoint[1] - centroid[1];
701 dV[2] = currentPoint[2] - centroid[2];
702 vtkMath::Normalize(dV);
703 vtkMath::MultiplyScalar(dV, direction);
704 vtkMath::Add(currentPoint, dV, mdfdPoint);
705 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
706 wsp->SetCollectionPoint(group, i, modPoint);
711 printf("PG ShowNPoints_Tools::ExpandPatch Warning groups, points or params invalid. need 3 groups of points, need 4 params(centroid, and direction 1 or -1)\n");
715 wsp->UndoRedo_SaveCollection();
719 * Given a cutting surface, expand the distance between the edge splines and the middle spline. making it "wider" or "thicker".
721 void ShowNPoints_Tools::WidenSurface()
723 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
724 wsp->StopAutoAddPoints();
725 wsp->StopTrackPoint();
727 if((wsp->GetLstModelShowNPointsSize()==2)
728 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
729 && (bbGetInputParams().size() == 4))
731 double direction = bbGetInputParams()[3];
732 double normal[3] = {bbGetInputParams()[0], bbGetInputParams()[1], bbGetInputParams()[2]};
733 vtkMath::MultiplyScalar(normal, direction);
735 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
736 double pointSp1[3], pointSp2[3];
737 std::vector<double> modifiedPoint;
738 for(int i = 0; i < pointsPerSpline; i++){
739 wsp->GetCollectionPoint(0, i, pointSp1);
740 wsp->GetCollectionPoint(1, i, pointSp2);
741 vtkMath::Add(pointSp1, normal, pointSp1);
742 vtkMath::Subtract(pointSp2, normal, pointSp2);
743 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp1), std::end(pointSp1));
744 wsp->SetCollectionPoint(0, i, modifiedPoint);
745 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp2), std::end(pointSp2));
746 wsp->SetCollectionPoint(1, i, modifiedPoint);
750 printf("PG ShowNPoints_Tools::WidenSurface Warning surface not apply. groups, points or params invalid. need 3 group of points, need 4 params(normal and direction)\n");
754 wsp->UndoRedo_SaveCollection();
757 void ShowNPoints_Tools::MovePointInNormal()
759 //move the currently selected control point in the direction or opposite of the normal vector of the closest point in the input mesh
761 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
762 wsp->StopAutoAddPoints();
763 wsp->StopTrackPoint();
764 if((wsp->GetLstModelShowNPointsSize()>=2) //Check condition
765 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
766 && (bbGetInputParams().size() == 1)
767 && (bbGetInputMesh() != NULL)
768 && (bbGetInputSpacing().size() == 3))
770 if(bbGetInputParams()[0] != -1 && bbGetInputParams()[0] != 1){
771 printf("PG ShowNPoints_Tools::MovePointInNormal No direction provided, must be 1 or -1");
776 double p[3], normal[3];; // point to modify and normal
777 std::vector<double> pN(3); // new point
779 spc[0] = bbGetInputSpacing()[0];
780 spc[1] = bbGetInputSpacing()[1];
781 spc[2] = bbGetInputSpacing()[2];
783 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
784 pointLocator->SetDataSet( bbGetInputMesh() );
785 pointLocator->BuildLocator();
787 // int idControlPoint = wsp->GetModelShowNPoints()->GetNearestPoint();
788 int idControlPoint = wsp->GetModelShowNPoints()->GetIdCurrentPoint();
790 if(idControlPoint >= 0){
791 wsp->GetModelShowNPoints()->GetIdPoint(idControlPoint, &x, &y, &z);
795 int idMeshPoint = pointLocator->FindClosestPoint(p);
796 bbGetInputMesh()->GetPointData()->GetNormals()->GetTuple(idMeshPoint, normal);
797 int direction = bbGetInputParams()[0];
798 pN[0] = p[0] / spc[0] + direction*normal[0];
799 pN[1] = p[1] / spc[1] + direction*normal[1];
800 pN[2] = p[2] / spc[2] + direction*normal[2];
802 wsp->GetModelShowNPoints()->SetPointById(idControlPoint, pN);
803 // wsp->GetViewShowNPoints()->RefreshPoint(idControlPoint);
804 wsp->RefreshCollectionText();
805 wsp->RefreshColourCollection();
807 wsp->UndoRedo_SaveCollection();
808 } // if idControlPoint
809 } // if wsp->GetLstModelShowNPointsSiz->size()>=2
812 void ShowNPoints_Tools::ChangeCurrentPoint()
814 if(bbGetInputParams()[0] != -1 && bbGetInputParams()[0] != 1){
815 printf("PG ShowNPoints_Tools::MovePointInNormal No direction provided, must be 1 or -1");
818 int step=bbGetInputParams()[0];
819 WidgetShowNPoints *wsp = bbGetInputWidgetShowNPoints();
820 int idControlPoint = wsp->GetModelShowNPoints()->GetIdCurrentPoint() + step;
821 int size=wsp->GetModelShowNPoints()->GetLstPointsSize();
822 if (idControlPoint<0) { idControlPoint = size-1; }
823 if (idControlPoint>=size ) { idControlPoint = 0; }
824 wsp->GetModelShowNPoints()->SetIdCurrentPoint( idControlPoint );
825 wsp->RefreshCollectionText();
826 wsp->RefreshColourCollection();
829 void ShowNPoints_Tools::JoinPoints()
831 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
832 wsp->StopAutoAddPoints();
833 wsp->StopTrackPoint();
834 if((wsp->GetLstModelShowNPointsSize()>=2)
835 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
837 int numberOfSplines = wsp->GetLstModelShowNPointsSize();
839 int sizeCurrentSpline, i;
840 wsp->GetModelShowNPoints()->GetIdPoint(0, &x, &y, &z);
841 std::vector<double> pointStart = {x, y, z};
842 sizeCurrentSpline = wsp->GetModelShowNPoints()->GetLstPointsX().size();
843 wsp->GetModelShowNPoints()->GetIdPoint(sizeCurrentSpline-1, &x, &y, &z);
844 std::vector<double> pointEnd = {x, y, z};
845 for(i = 0; i < numberOfSplines; i++){
846 sizeCurrentSpline = wsp->GetModelShowNPoints(i)->GetLstPointsX().size();
847 wsp->SetCollectionPoint(i, 0, pointStart);
848 wsp->SetCollectionPoint(i, sizeCurrentSpline-1, pointEnd);
851 wsp->UndoRedo_SaveCollection();
855 void ShowNPoints_Tools::SetMesh()
857 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
858 wsp->SetAuxMesh(bbGetInputMesh(), bbGetInputSpacing(), bbGetInputParams() );
862 // 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)
864 void ShowNPoints_Tools::Process()
867 // THE MAIN PROCESSING METHOD BODY
868 // Here we simply set the input 'In' value to the output 'Out'
869 // And print out the output value
870 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
871 // void bbSet{Input|Output}NAME(const TYPE&)
872 // const TYPE& bbGet{Input|Output}NAME() const
874 // * NAME is the name of the input/output
875 // (the one provided in the attribute 'name' of the tag 'input')
876 // * TYPE is the C++ type of the input/output
877 // (the one provided in the attribute 'type' of the tag 'input')
879 // bbSetOutputOut( bbGetInputIn() );
880 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
882 if (bbGetInputWidgetShowNPoints()!=NULL)
884 if (bbGetInputType()==1)
886 bbGetInputWidgetShowNPoints()->OnAutoAddPoints_tool();
889 if (bbGetInputType()==5)
891 bbGetInputWidgetShowNPoints()->OnAddPoint_();
893 if (bbGetInputType()==10)
895 bbGetInputWidgetShowNPoints()->OnInsertPoint_();
897 if (bbGetInputType()==20)
899 bbGetInputWidgetShowNPoints()->OnTrackPoint_tool();
901 if (bbGetInputType()==30)
903 bbGetInputWidgetShowNPoints()->OnSetPoint_();
905 if (bbGetInputType()==40)
907 bbGetInputWidgetShowNPoints()->OnErasePoint_();
909 if (bbGetInputType()==50)
911 bbGetInputWidgetShowNPoints()->OnDeleteAllPoints_();
913 if (bbGetInputType()==100)
915 bbGetInputWidgetShowNPoints()->OnInsertCollectionAfter_();
917 if (bbGetInputType()==110)
919 bbGetInputWidgetShowNPoints()->OnDeleteCollection_();
921 if (bbGetInputType()==120)
923 bbGetInputWidgetShowNPoints()->OnResetCollections_();
925 if (bbGetInputType()==200) // Create patch surface
927 InitCreatePatch_Points();
929 if (bbGetInputType()==205) // Create volume surface from points
931 InitCreateVolumeSurface_Points();
933 if (bbGetInputType()==210)
935 bbGetInputWidgetShowNPoints()->OnInvertLstPoints_();
937 if(bbGetInputType()==220)
941 if(bbGetInputType()==230)
945 if(bbGetInputType()==235)
947 ChangeCurrentPoint();
949 if(bbGetInputType()==240)
953 if(bbGetInputType()==250)
957 if(bbGetInputType()==300)
959 CreateExpandedSurface();
961 if(bbGetInputType()==310)
963 CreateWideExpandedSurface();
965 if(bbGetInputType()==320)
969 if(bbGetInputType()==330)
973 if(bbGetInputType()==340)
977 } // if bbGetInputWidgetShowNPoints
980 // 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)
982 void ShowNPoints_Tools::bbUserSetDefaultValues()
984 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
985 // Here we initialize the input 'In' to 0
987 bbSetInputMesh(NULL);
988 bbSetInputWidgetShowNPoints(NULL);
990 std::vector<double> spc;
994 bbSetInputSpacing(spc);
997 // 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)
999 void ShowNPoints_Tools::bbUserInitializeProcessing()
1001 // THE INITIALIZATION METHOD BODY :
1002 // Here does nothing
1003 // but this is where you should allocate the internal/output pointers
1007 // 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)
1009 void ShowNPoints_Tools::bbUserFinalizeProcessing()
1011 // THE FINALIZATION METHOD BODY :
1012 // Here does nothing
1013 // but this is where you should desallocate the internal/output pointers
1017 } // EO namespace bbcreaMaracasVisu