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 void ShowNPoints_Tools::InitCreateVolumeSurface_Points()
143 InitCreatePatch_Points(); // 1 group -> 3 groups
145 // 3 groups to 4 groups
146 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
147 wsp->StopAutoAddPoints();
148 wsp->StopTrackPoint();
149 if( wsp->GetLstModelShowNPointsSize()==3 )
152 double pC1[3]; // fist point
154 double pC2A[3]; // first middle point
155 double pC2B[3]; // second midle point
156 double pC3[3]; // last point
157 double pN[3]; // new over the surface
159 vtkPoints *points = bbGetInputMesh()->GetPoints();
160 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
161 pointLocator->SetDataSet( bbGetInputMesh() );
162 pointLocator->BuildLocator();
163 spc[0] = bbGetInputSpacing()[0];
164 spc[1] = bbGetInputSpacing()[1];
165 spc[2] = bbGetInputSpacing()[2];
166 wsp->InsertCollectionAfter_();
167 wsp->GetCollectionPoint(1,0, pC1);
168 wsp->GetCollectionPoint(1,2, pC3);
172 pC2A[0]=pC1[0]+dx*0.33333; pC2A[1]=pC1[1]+dy*0.3333; pC2A[2]=pC1[2]+dz*0.33333;
173 pC2B[0]=pC1[0]+dx*0.66666; pC2B[1]=pC1[1]+dy*0.6666; pC2B[2]=pC1[2]+dz*0.66666;
175 wsp->InsertPoint(pC1[0] ,pC1[1], pC1[2],"");
177 NearestPointToMesh(points, pointLocator, spc, pC2A,pN);
178 wsp->InsertPoint(pN[0] ,pN[1], pN[2],"");
180 NearestPointToMesh(points, pointLocator, spc, pC2B,pN);
181 wsp->InsertPoint(pN[0] ,pN[1], pN[2],"");
183 wsp->InsertPoint(pC3[0] ,pC3[1], pC3[2],"");
186 // Add points to the other Groups
187 std::vector<double> pointStart;
188 pointStart.push_back( pC1[0] );
189 pointStart.push_back( pC1[1] );
190 pointStart.push_back( pC1[2] );
191 std::vector<double> pointEnd;
192 pointEnd.push_back( pC3[0] );
193 pointEnd.push_back( pC3[1] );
194 pointEnd.push_back( pC3[2] );
196 wsp->SetActualCollection(0);
197 wsp->SetReferencePoint(pointStart);
198 wsp->OnInsertPoint_();
199 wsp->SetReferencePoint(pointEnd);
200 wsp->OnInsertPoint_();
202 wsp->SetActualCollection(2);
203 wsp->SetReferencePoint(pointStart);
204 wsp->OnInsertPoint_();
205 wsp->SetReferencePoint(pointEnd);
206 wsp->OnInsertPoint_();
210 wsp->UndoRedo_SaveCollection();
216 void ShowNPoints_Tools::CreatePatch_Points(std::vector<double> lstX, std::vector<double> lstY, std::vector<double> lstZ)
218 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
219 std::vector<long int> lstIdNormalSurface;
221 spc[0] = bbGetInputSpacing()[0];
222 spc[1] = bbGetInputSpacing()[1];
223 spc[2] = bbGetInputSpacing()[2];
224 vtkPoints *points = bbGetInputMesh()->GetPoints();
225 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
226 pointLocator->SetDataSet( bbGetInputMesh() );
227 pointLocator->BuildLocator();
228 wsp->StopTrackPoint();
232 wsp->DeleteAllPoints_();
233 //wsp->ErasePoint( 0 );
234 //wsp->ErasePoint( 0 );
235 //wsp->ErasePoint( 0 );
236 //wsp->ErasePoint( 0 );
238 dx = lstX[1]-lstX[0];
239 dy = lstY[1]-lstY[0];
240 dz = lstZ[1]-lstZ[0];
244 for(int sect = 0; sect < 5; sect++)
246 p[0] = lstX[0] + dx*(sect*part);
247 p[1] = lstY[0] + dy*(sect*part);
248 p[2] = lstZ[0] + dz*(sect*part);
250 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
251 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
252 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
255 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
256 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
257 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
259 NearestPointToMesh(points, pointLocator, spc, p,pM);
260 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
261 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
267 wsp->InsertCollectionAfter_();
268 p[0] = (lstX[0]+lstX[3])/2;
269 p[1] = (lstY[0]+lstY[3])/2;
270 p[2] = (lstZ[0]+lstZ[3])/2;
271 NearestPointToMesh(points, pointLocator, spc, p,pM);
272 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
273 p[0] = (lstX[1]+lstX[2])/2;
274 p[1] = (lstY[1]+lstY[2])/2;
275 p[2] = (lstZ[1]+lstZ[2])/2;
276 NearestPointToMesh(points, pointLocator, spc, p,pM);
277 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
278 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;
279 wsp->InsertPoint(p[0] ,p[1], p[2],"");
280 std::copy(std::begin(p), std::end(p), std::begin(centroid));
282 wsp->InsertCollectionAfter_();
283 dx = lstX[2]-lstX[3];
284 dy = lstY[2]-lstY[3];
285 dz = lstZ[2]-lstZ[3];
286 for(int sect = 0; sect < 5; sect++)
288 p[0] = lstX[3] + dx*(sect*part);
289 p[1] = lstY[3] + dy*(sect*part);
290 p[2] = lstZ[3] + dz*(sect*part);
292 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
293 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
294 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
297 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
298 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
299 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
301 NearestPointToMesh(points, pointLocator, spc, p,pM);
302 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
303 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
305 pointLocator->Delete();
307 // 1. Recorrer las normales de lstIdNormals y calcular el promedio -> V1
310 vtkPointData *pointdata = bbGetInputMesh()->GetPointData();
311 vtkDataArray *dataarray = pointdata->GetNormals();
312 int i,size = lstIdNormalSurface.size();
316 for (i=0; i<size; i++)
318 nValue = dataarray->GetTuple3( lstIdNormalSurface[i] );
319 n1[0] = n1[0] + nValue[0];
320 n1[1] = n1[1] + nValue[1];
321 n1[2] = n1[2] + nValue[2];
327 // 2. Calcular el promedio de 4 normales de la nueva superficie -> V2
335 // Collection 0 with 4 points
336 // Collection 1 with 3 points
337 // Collection 2 with 4 points
338 wsp->GetCollectionPoint(1,1, pC);
340 wsp->GetCollectionPoint(0,0, pM);
341 vtkMath::Subtract(pM,pC,pM1);
342 wsp->GetCollectionPoint(0,3, pM);
343 vtkMath::Subtract(pM,pC,pM2);
344 vtkMath::Cross(pM1,pM2,pM);
349 wsp->GetCollectionPoint(0,3, pM);
350 vtkMath::Subtract(pM,pC,pM1);
351 wsp->GetCollectionPoint(2,3, pM);
352 vtkMath::Subtract(pM,pC,pM2);
353 vtkMath::Cross(pM1,pM2,pM);
354 n2[0] = n2[0] + pM[0];
355 n2[1] = n2[1] + pM[1];
356 n2[2] = n2[2] + pM[2];
358 wsp->GetCollectionPoint(2,3, pM);
359 vtkMath::Subtract(pM,pC,pM1);
360 wsp->GetCollectionPoint(2,0, pM);
361 vtkMath::Subtract(pM,pC,pM2);
362 vtkMath::Cross(pM1,pM2,pM);
363 n2[0] = n2[0] + pM[0];
364 n2[1] = n2[1] + pM[1];
365 n2[2] = n2[2] + pM[2];
367 wsp->GetCollectionPoint(2,0, pM);
368 vtkMath::Subtract(pM,pC,pM1);
369 wsp->GetCollectionPoint(0,0, pM);
370 vtkMath::Subtract(pM,pC,pM2);
371 vtkMath::Cross(pM1,pM2,pM);
372 n2[0] = n2[0] + pM[0];
373 n2[1] = n2[1] + pM[1];
374 n2[2] = n2[2] + pM[2];
380 // 3. Calcular el angulo entre V1 y V2
381 double angle = vtkMath::AngleBetweenVectors(n1,n2) * 180 / vtkMath::Pi();
382 // 4. Si el angulo es major de 90 Invertir las normales de la superficie actual
385 vtkMath::MultiplyScalar(n2, -1);
386 wsp->InvertLstPoints_();
388 std::vector<double> normalOut(n2, n2 + 3);
389 double norm = vtkMath::Norm(n2);
390 normalOut[0] = normalOut[0]/norm;
391 normalOut[1] = normalOut[1]/norm;
392 normalOut[2] = normalOut[2]/norm;
394 std::vector<double> outputData;
395 outputData.insert(outputData.end(), ¢roid[0], ¢roid[3]);
396 outputData.insert(outputData.end(), &normalOut[0], &normalOut[3]);
398 bbSetOutputOut(outputData);
399 //bbSetOutputOut(normalOut);
403 wsp->UndoRedo_SaveCollection();
406 void ShowNPoints_Tools::MovePatchCenter()
408 std::vector<double> params = bbGetInputParams();
409 if(params.size() == 4)
411 if(params[3] != 1 && params[3] != -1)
413 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. direction of movement should be 1 or -1\n");
417 double centerPoint[3];
418 std::vector<double> normal, modPoint;
420 normal.push_back(params[0]);
421 normal.push_back(params[1]);
422 normal.push_back(params[2]);
424 int direction = -1 * params[3];
426 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
427 wsp->GetCollectionPoint(1,1, centerPoint);
428 modPoint.push_back(centerPoint[0] + direction * normal[0]);
429 modPoint.push_back(centerPoint[1] + direction * normal[1]);
430 modPoint.push_back(centerPoint[2] + direction * normal[2]);
432 wsp->SetCollectionPoint(1, 1, modPoint);
436 wsp->UndoRedo_SaveCollection();
438 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. Need 4: normal x y z and direction of movement (1 or -1)\n");
443 * Creates a cutting surface with 1 group of points. This surface can have its area adjusted
444 * (increase or decrease the distance from the points to the center)
445 * The centroid is set as the output, to be used by the expanding tool.
447 void ShowNPoints_Tools::CreateExpandedSurface()
450 //Set Input to 0 as this function should only be executed manually but still update its children.
454 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
455 wsp->StopAutoAddPoints();
456 wsp->StopTrackPoint();
457 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
459 //Set Input to 0 as this function should only be executed manually but still update its children.
462 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
463 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
464 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
466 wsp->DeleteAllPoints_();
469 for(int i = 0; i < (int)lstX.size(); i++){
470 centroid[0] += lstX[i];
471 centroid[1] += lstY[i];
472 centroid[2] += lstZ[i];
474 centroid[0] /= lstX.size();
475 centroid[1] /= lstX.size();
476 centroid[2] /= lstX.size();
481 for(int i = 0; i < (int)lstX.size(); i++){
482 dV[0] = lstX[i] - centroid[0];
483 dV[1] = lstY[i] - centroid[1];
484 dV[2] = lstZ[i] - centroid[2];
485 vtkMath::Normalize(dV);
487 p[0] = lstX[i] + 4*dV[0];
488 p[1] = lstY[i] + 4*dV[1];
489 p[2] = lstZ[i] + 4*dV[2];
490 wsp->AddPoint(p[0] ,p[1], p[2],"");
492 std::vector<double> outData = {centroid[0], centroid[1], centroid[2]};
493 bbSetOutputOut(outData);
496 printf("PG ShowNPoints_Tools::CreateExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
500 wsp->UndoRedo_SaveCollection();
504 * Creates a cutting surface with 3 groups of points. This surface can have its area adjusted
505 * (Increase or decrease distance from points to centroid of spline or distance between splines)
506 * The centroid and normal is set as the Output, to be used by the expanding tools.
508 void ShowNPoints_Tools::CreateWideExpandedSurface()
511 //Set Input to 0 as this function is only used by the popup menu
515 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
516 wsp->StopAutoAddPoints();
517 wsp->StopTrackPoint();
519 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
521 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
522 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
523 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
525 wsp->DeleteAllPoints_();
530 for(int i = 0; i < (int)lstX.size(); i++){
531 centroid[0] += lstX[i];
532 centroid[1] += lstY[i];
533 centroid[2] += lstZ[i];
535 centroid[0] /= lstX.size();
536 centroid[1] /= lstX.size();
537 centroid[2] /= lstX.size();
540 double currNormal[3];
542 for(int i = 0; i < ((int)lstX.size())-1; i++){
543 v1[0] = lstX[i] - centroid[0];
544 v1[1] = lstY[i] - centroid[1];
545 v1[2] = lstZ[i] - centroid[2];
546 v2[0] = lstX[i+1] - centroid[0];
547 v2[1] = lstY[i+1] - centroid[1];
548 v2[2] = lstZ[i+1] - centroid[2];
549 vtkMath::Cross(v1, v2, currNormal);
550 normal[0] += currNormal[0];
551 normal[1] += currNormal[1];
552 normal[2] += currNormal[2];
555 normal[0] /= (lstX.size()-1);
556 normal[1] /= (lstX.size()-1);
557 normal[2] /= (lstX.size()-1);
559 vtkMath::Normalize(normal);
563 //Add new groups on both sides from the original spline
564 for(int group = 0; group < 2; group++){
565 for(int i = 0; i < (int) lstX.size(); i++){
566 dV[0] = lstX[i] - centroid[0];
567 dV[1] = lstY[i] - centroid[1];
568 dV[2] = lstZ[i] - centroid[2];
569 vtkMath::Normalize(dV);
571 np[0] = lstX[i] + dV[0]*4 + ((normal[0]*2)*addNormal);
572 np[1] = lstY[i] + dV[1]*4 + ((normal[1]*2)*addNormal);
573 np[2] = lstZ[i] + dV[2]*4 + ((normal[2]*2)*addNormal);
574 wsp->AddPoint(np[0] ,np[1], np[2],"");
577 if(group < 1)wsp->InsertCollectionAfter_();
580 std::vector<double> outData = {centroid[0], centroid[1], centroid[2], normal[0], normal[1], normal[2]};
581 bbSetOutputOut(outData);
585 wsp->UndoRedo_SaveCollection();
588 printf("PG ShowNPoints_Tools::CreateWideExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
593 * Given a cutting surface, expand its area by moving the points outwards of the main centroid.
595 void ShowNPoints_Tools::ExpandSurfaceArea()
597 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
598 wsp->StopAutoAddPoints();
599 wsp->StopTrackPoint();
601 if((wsp->GetLstModelShowNPointsSize()==1 || wsp->GetLstModelShowNPointsSize() == 2)
602 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
603 && (bbGetInputParams().size() == 4))
605 std::vector<double> params = bbGetInputParams();
606 double direction = params[3];
607 double centroid[3] = {params[0], params[1], params[2]};
609 double dV[3], currPoint[3], mdfdPoint[3];
611 std::vector<double> modPoint;
612 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
613 for(int i = 0; i < pointsPerSpline; i++){
614 wsp->GetCollectionPoint(0, i, currPoint);
615 dV[0] = currPoint[0] - centroid[0];
616 dV[1] = currPoint[1] - centroid[1];
617 dV[2] = currPoint[2] - centroid[2];
618 vtkMath::Normalize(dV);
620 vtkMath::MultiplyScalar(dV, direction);
621 vtkMath::Add(currPoint, dV, mdfdPoint);
622 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
623 wsp->SetCollectionPoint(0, i, modPoint);
625 if(wsp->GetLstModelShowNPointsSize() == 2){
626 wsp->GetCollectionPoint(1, i, currPoint);
627 vtkMath::Add(currPoint, dV, mdfdPoint);
628 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
629 wsp->SetCollectionPoint(1, i, modPoint);
634 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");
638 wsp->UndoRedo_SaveCollection();
641 void ShowNPoints_Tools::ExpandPatch()
643 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
644 wsp->StopAutoAddPoints();
645 wsp->StopTrackPoint();
646 if((wsp->GetLstModelShowNPointsSize() == 3)
647 && (wsp->GetLstPointsX().size() == 13)
648 && (bbGetInputParams().size() == 4))
650 std::vector<double> params = bbGetInputParams();
651 double direction = params[3];
652 double centroid[3] = {params[0], params[1], params[2]};
654 std::vector<double> modPoint(3);
655 double currentPoint[3], dV[3], mdfdPoint[3];
656 for(int group = 0; group < 3; group++){
658 wsp->GetCollectionPoint(group, 0, currentPoint);
659 dV[0] = currentPoint[0] - centroid[0];
660 dV[1] = currentPoint[1] - centroid[1];
661 dV[2] = currentPoint[2] - centroid[2];
662 vtkMath::Normalize(dV);
663 vtkMath::MultiplyScalar(dV, direction);
664 vtkMath::Add(currentPoint, dV, mdfdPoint);
665 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
666 wsp->SetCollectionPoint(group, 0, modPoint);
667 wsp->GetCollectionPoint(group, 2, currentPoint);
668 dV[0] = currentPoint[0] - centroid[0];
669 dV[1] = currentPoint[1] - centroid[1];
670 dV[2] = currentPoint[2] - centroid[2];
671 vtkMath::Normalize(dV);
672 vtkMath::MultiplyScalar(dV, direction);
673 vtkMath::Add(currentPoint, dV, mdfdPoint);
674 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
675 wsp->SetCollectionPoint(group, 2, modPoint);
677 for(int i = 0; i < 5; i++){
678 wsp->GetCollectionPoint(group,i, 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, i, modPoint);
691 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");
695 wsp->UndoRedo_SaveCollection();
699 * Given a cutting surface, expand the distance between the edge splines and the middle spline. making it "wider" or "thicker".
701 void ShowNPoints_Tools::WidenSurface()
703 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
704 wsp->StopAutoAddPoints();
705 wsp->StopTrackPoint();
707 if((wsp->GetLstModelShowNPointsSize()==2)
708 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
709 && (bbGetInputParams().size() == 4))
711 double direction = bbGetInputParams()[3];
712 double normal[3] = {bbGetInputParams()[0], bbGetInputParams()[1], bbGetInputParams()[2]};
713 vtkMath::MultiplyScalar(normal, direction);
715 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
716 double pointSp1[3], pointSp2[3];
717 std::vector<double> modifiedPoint;
718 for(int i = 0; i < pointsPerSpline; i++){
719 wsp->GetCollectionPoint(0, i, pointSp1);
720 wsp->GetCollectionPoint(1, i, pointSp2);
721 vtkMath::Add(pointSp1, normal, pointSp1);
722 vtkMath::Subtract(pointSp2, normal, pointSp2);
723 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp1), std::end(pointSp1));
724 wsp->SetCollectionPoint(0, i, modifiedPoint);
725 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp2), std::end(pointSp2));
726 wsp->SetCollectionPoint(1, i, modifiedPoint);
730 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");
734 wsp->UndoRedo_SaveCollection();
737 void ShowNPoints_Tools::MovePointInNormal()
739 //move the currently selected control point in the direction or opposite of the normal vector of the closest point in the input mesh
741 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
742 wsp->StopAutoAddPoints();
743 wsp->StopTrackPoint();
744 if((wsp->GetLstModelShowNPointsSize()>=2) //Check condition
745 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
746 && (bbGetInputParams().size() == 1)
747 && (bbGetInputMesh() != NULL)
748 && (bbGetInputSpacing().size() == 3))
750 if(bbGetInputParams()[0] != -1 && bbGetInputParams()[0] != 1){
751 printf("PG ShowNPoints_Tools::MovePointInNormal No direction provided, must be 1 or -1");
756 double p[3], normal[3];; // point to modify and normal
757 std::vector<double> pN(3); // new point
759 spc[0] = bbGetInputSpacing()[0];
760 spc[1] = bbGetInputSpacing()[1];
761 spc[2] = bbGetInputSpacing()[2];
763 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
764 pointLocator->SetDataSet( bbGetInputMesh() );
765 pointLocator->BuildLocator();
767 // int idControlPoint = wsp->GetModelShowNPoints()->GetNearestPoint();
768 int idControlPoint = wsp->GetModelShowNPoints()->GetIdCurrentPoint();
770 if(idControlPoint >= 0){
771 wsp->GetModelShowNPoints()->GetIdPoint(idControlPoint, &x, &y, &z);
775 int idMeshPoint = pointLocator->FindClosestPoint(p);
776 bbGetInputMesh()->GetPointData()->GetNormals()->GetTuple(idMeshPoint, normal);
777 int direction = bbGetInputParams()[0];
778 pN[0] = p[0] / spc[0] + direction*normal[0];
779 pN[1] = p[1] / spc[1] + direction*normal[1];
780 pN[2] = p[2] / spc[2] + direction*normal[2];
782 wsp->GetModelShowNPoints()->SetPointById(idControlPoint, pN);
783 wsp->GetViewShowNPoints()->RefreshPoint(idControlPoint);
785 wsp->UndoRedo_SaveCollection();
786 } // if idControlPoint
790 void ShowNPoints_Tools::ChangeCurrentPoint()
792 if(bbGetInputParams()[0] != -1 && bbGetInputParams()[0] != 1){
793 printf("PG ShowNPoints_Tools::MovePointInNormal No direction provided, must be 1 or -1");
796 int step=bbGetInputParams()[0];
797 WidgetShowNPoints *wsp = bbGetInputWidgetShowNPoints();
798 int idControlPoint = wsp->GetModelShowNPoints()->GetIdCurrentPoint() + step;
799 int size=wsp->GetModelShowNPoints()->GetLstPointsSize();
800 if (idControlPoint<0) { idControlPoint = size-1; }
801 if (idControlPoint>=size ) { idControlPoint = 0; }
802 wsp->GetModelShowNPoints()->SetIdCurrentPoint( idControlPoint );
803 wsp->RefreshCollectionText();
804 wsp->RefreshColourCollection();
807 void ShowNPoints_Tools::JoinPoints()
809 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
810 wsp->StopAutoAddPoints();
811 wsp->StopTrackPoint();
812 if((wsp->GetLstModelShowNPointsSize()>=2)
813 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
815 int numberOfSplines = wsp->GetLstModelShowNPointsSize();
817 int sizeCurrentSpline, i;
818 wsp->GetModelShowNPoints()->GetIdPoint(0, &x, &y, &z);
819 std::vector<double> pointStart = {x, y, z};
820 sizeCurrentSpline = wsp->GetModelShowNPoints()->GetLstPointsX().size();
821 wsp->GetModelShowNPoints()->GetIdPoint(sizeCurrentSpline-1, &x, &y, &z);
822 std::vector<double> pointEnd = {x, y, z};
823 for(i = 0; i < numberOfSplines; i++){
824 sizeCurrentSpline = wsp->GetModelShowNPoints(i)->GetLstPointsX().size();
825 wsp->SetCollectionPoint(i, 0, pointStart);
826 wsp->SetCollectionPoint(i, sizeCurrentSpline-1, pointEnd);
829 wsp->UndoRedo_SaveCollection();
834 // 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)
836 void ShowNPoints_Tools::Process()
839 // THE MAIN PROCESSING METHOD BODY
840 // Here we simply set the input 'In' value to the output 'Out'
841 // And print out the output value
842 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
843 // void bbSet{Input|Output}NAME(const TYPE&)
844 // const TYPE& bbGet{Input|Output}NAME() const
846 // * NAME is the name of the input/output
847 // (the one provided in the attribute 'name' of the tag 'input')
848 // * TYPE is the C++ type of the input/output
849 // (the one provided in the attribute 'type' of the tag 'input')
851 // bbSetOutputOut( bbGetInputIn() );
852 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
854 if (bbGetInputWidgetShowNPoints()!=NULL)
856 if (bbGetInputType()==1)
858 bbGetInputWidgetShowNPoints()->OnAutoAddPoints_tool();
861 if (bbGetInputType()==5)
863 bbGetInputWidgetShowNPoints()->OnAddPoint_();
865 if (bbGetInputType()==10)
867 bbGetInputWidgetShowNPoints()->OnInsertPoint_();
869 if (bbGetInputType()==20)
871 bbGetInputWidgetShowNPoints()->OnTrackPoint_tool();
873 if (bbGetInputType()==30)
875 bbGetInputWidgetShowNPoints()->OnSetPoint_();
877 if (bbGetInputType()==40)
879 bbGetInputWidgetShowNPoints()->OnErasePoint_();
881 if (bbGetInputType()==50)
883 bbGetInputWidgetShowNPoints()->OnDeleteAllPoints_();
885 if (bbGetInputType()==100)
887 bbGetInputWidgetShowNPoints()->OnInsertCollectionAfter_();
889 if (bbGetInputType()==110)
891 bbGetInputWidgetShowNPoints()->OnDeleteCollection_();
893 if (bbGetInputType()==120)
895 bbGetInputWidgetShowNPoints()->OnResetCollections_();
897 if (bbGetInputType()==200) // Create patch surface
899 InitCreatePatch_Points();
901 if (bbGetInputType()==205) // Create volume surface from points
903 InitCreateVolumeSurface_Points();
905 if (bbGetInputType()==210)
907 bbGetInputWidgetShowNPoints()->OnInvertLstPoints_();
909 if(bbGetInputType()==220)
913 if(bbGetInputType()==230)
917 if(bbGetInputType()==235)
919 ChangeCurrentPoint();
922 if(bbGetInputType()==240)
926 if(bbGetInputType()==300)
928 CreateExpandedSurface();
930 if(bbGetInputType()==310)
932 CreateWideExpandedSurface();
934 if(bbGetInputType()==320)
938 if(bbGetInputType()==330)
942 if(bbGetInputType()==340)
946 } // if bbGetInputWidgetShowNPoints
949 // 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)
951 void ShowNPoints_Tools::bbUserSetDefaultValues()
953 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
954 // Here we initialize the input 'In' to 0
956 bbSetInputMesh(NULL);
957 bbSetInputWidgetShowNPoints(NULL);
959 std::vector<double> spc;
963 bbSetInputSpacing(spc);
966 // 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)
968 void ShowNPoints_Tools::bbUserInitializeProcessing()
970 // THE INITIALIZATION METHOD BODY :
972 // but this is where you should allocate the internal/output pointers
976 // 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)
978 void ShowNPoints_Tools::bbUserFinalizeProcessing()
980 // THE FINALIZATION METHOD BODY :
982 // but this is where you should desallocate the internal/output pointers
986 } // EO namespace bbcreaMaracasVisu