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],"");
187 wsp->UndoRedo_SaveCollection();
193 void ShowNPoints_Tools::CreatePatch_Points(std::vector<double> lstX, std::vector<double> lstY, std::vector<double> lstZ)
195 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
196 std::vector<long int> lstIdNormalSurface;
198 spc[0] = bbGetInputSpacing()[0];
199 spc[1] = bbGetInputSpacing()[1];
200 spc[2] = bbGetInputSpacing()[2];
201 vtkPoints *points = bbGetInputMesh()->GetPoints();
202 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
203 pointLocator->SetDataSet( bbGetInputMesh() );
204 pointLocator->BuildLocator();
205 wsp->StopTrackPoint();
209 wsp->DeleteAllPoints_();
210 //wsp->ErasePoint( 0 );
211 //wsp->ErasePoint( 0 );
212 //wsp->ErasePoint( 0 );
213 //wsp->ErasePoint( 0 );
215 dx = lstX[1]-lstX[0];
216 dy = lstY[1]-lstY[0];
217 dz = lstZ[1]-lstZ[0];
221 for(int sect = 0; sect < 5; sect++)
223 p[0] = lstX[0] + dx*(sect*part);
224 p[1] = lstY[0] + dy*(sect*part);
225 p[2] = lstZ[0] + dz*(sect*part);
227 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
228 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
229 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
232 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
233 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
234 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
236 NearestPointToMesh(points, pointLocator, spc, p,pM);
237 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
238 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
244 wsp->InsertCollectionAfter_();
245 p[0] = (lstX[0]+lstX[3])/2;
246 p[1] = (lstY[0]+lstY[3])/2;
247 p[2] = (lstZ[0]+lstZ[3])/2;
248 NearestPointToMesh(points, pointLocator, spc, p,pM);
249 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
250 p[0] = (lstX[1]+lstX[2])/2;
251 p[1] = (lstY[1]+lstY[2])/2;
252 p[2] = (lstZ[1]+lstZ[2])/2;
253 NearestPointToMesh(points, pointLocator, spc, p,pM);
254 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
255 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;
256 wsp->InsertPoint(p[0] ,p[1], p[2],"");
257 std::copy(std::begin(p), std::end(p), std::begin(centroid));
259 wsp->InsertCollectionAfter_();
260 dx = lstX[2]-lstX[3];
261 dy = lstY[2]-lstY[3];
262 dz = lstZ[2]-lstZ[3];
263 for(int sect = 0; sect < 5; sect++)
265 p[0] = lstX[3] + dx*(sect*part);
266 p[1] = lstY[3] + dy*(sect*part);
267 p[2] = lstZ[3] + dz*(sect*part);
269 p[0] = p[0] + 0.5*(((lstX[1]+lstX[2])/2)-p[0]);
270 p[1] = p[1] + 0.5*(((lstY[1]+lstY[2])/2)-p[1]);
271 p[2] = p[2] + 0.5*(((lstZ[1]+lstZ[2])/2)-p[2]);
274 p[0] = p[0] + 0.5*(((lstX[0]+lstX[3])/2)-p[0]);
275 p[1] = p[1] + 0.5*(((lstY[0]+lstY[3])/2)-p[1]);
276 p[2] = p[2] + 0.5*(((lstZ[0]+lstZ[3])/2)-p[2]);
278 NearestPointToMesh(points, pointLocator, spc, p,pM);
279 wsp->InsertPoint(pM[0] ,pM[1], pM[2],"");
280 if(sect == 0 || sect == 4) lstIdNormalSurface.push_back( pointLocator->FindClosestPoint(pM) );
282 pointLocator->Delete();
284 // 1. Recorrer las normales de lstIdNormals y calcular el promedio -> V1
287 vtkPointData *pointdata = bbGetInputMesh()->GetPointData();
288 vtkDataArray *dataarray = pointdata->GetNormals();
289 int i,size = lstIdNormalSurface.size();
293 for (i=0; i<size; i++)
295 nValue = dataarray->GetTuple3( lstIdNormalSurface[i] );
296 n1[0] = n1[0] + nValue[0];
297 n1[1] = n1[1] + nValue[1];
298 n1[2] = n1[2] + nValue[2];
304 // 2. Calcular el promedio de 4 normales de la nueva superficie -> V2
312 // Collection 0 with 4 points
313 // Collection 1 with 3 points
314 // Collection 2 with 4 points
315 wsp->GetCollectionPoint(1,1, pC);
317 wsp->GetCollectionPoint(0,0, pM);
318 vtkMath::Subtract(pM,pC,pM1);
319 wsp->GetCollectionPoint(0,3, pM);
320 vtkMath::Subtract(pM,pC,pM2);
321 vtkMath::Cross(pM1,pM2,pM);
326 wsp->GetCollectionPoint(0,3, pM);
327 vtkMath::Subtract(pM,pC,pM1);
328 wsp->GetCollectionPoint(2,3, pM);
329 vtkMath::Subtract(pM,pC,pM2);
330 vtkMath::Cross(pM1,pM2,pM);
331 n2[0] = n2[0] + pM[0];
332 n2[1] = n2[1] + pM[1];
333 n2[2] = n2[2] + pM[2];
335 wsp->GetCollectionPoint(2,3, pM);
336 vtkMath::Subtract(pM,pC,pM1);
337 wsp->GetCollectionPoint(2,0, pM);
338 vtkMath::Subtract(pM,pC,pM2);
339 vtkMath::Cross(pM1,pM2,pM);
340 n2[0] = n2[0] + pM[0];
341 n2[1] = n2[1] + pM[1];
342 n2[2] = n2[2] + pM[2];
344 wsp->GetCollectionPoint(2,0, pM);
345 vtkMath::Subtract(pM,pC,pM1);
346 wsp->GetCollectionPoint(0,0, pM);
347 vtkMath::Subtract(pM,pC,pM2);
348 vtkMath::Cross(pM1,pM2,pM);
349 n2[0] = n2[0] + pM[0];
350 n2[1] = n2[1] + pM[1];
351 n2[2] = n2[2] + pM[2];
357 // 3. Calcular el angulo entre V1 y V2
358 double angle = vtkMath::AngleBetweenVectors(n1,n2) * 180 / vtkMath::Pi();
359 // 4. Si el angulo es major de 90 Invertir las normales de la superficie actual
362 vtkMath::MultiplyScalar(n2, -1);
363 wsp->InvertLstPoints_();
365 std::vector<double> normalOut(n2, n2 + 3);
366 double norm = vtkMath::Norm(n2);
367 normalOut[0] = normalOut[0]/norm;
368 normalOut[1] = normalOut[1]/norm;
369 normalOut[2] = normalOut[2]/norm;
371 std::vector<double> outputData;
372 outputData.insert(outputData.end(), ¢roid[0], ¢roid[3]);
373 outputData.insert(outputData.end(), &normalOut[0], &normalOut[3]);
375 bbSetOutputOut(outputData);
376 //bbSetOutputOut(normalOut);
380 wsp->UndoRedo_SaveCollection();
383 void ShowNPoints_Tools::MovePatchCenter()
385 std::vector<double> params = bbGetInputParams();
386 if(params.size() == 4)
388 if(params[3] != 1 && params[3] != -1)
390 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. direction of movement should be 1 or -1\n");
394 double centerPoint[3];
395 std::vector<double> normal, modPoint;
397 normal.push_back(params[0]);
398 normal.push_back(params[1]);
399 normal.push_back(params[2]);
401 int direction = -1 * params[3];
403 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
404 wsp->GetCollectionPoint(1,1, centerPoint);
405 modPoint.push_back(centerPoint[0] + direction * normal[0]);
406 modPoint.push_back(centerPoint[1] + direction * normal[1]);
407 modPoint.push_back(centerPoint[2] + direction * normal[2]);
409 wsp->SetCollectionPoint(1, 1, modPoint);
413 wsp->UndoRedo_SaveCollection();
415 printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. Need 4: normal x y z and direction of movement (1 or -1)\n");
420 * Creates a cutting surface with 1 group of points. This surface can have its area adjusted
421 * (increase or decrease the distance from the points to the center)
422 * The centroid is set as the output, to be used by the expanding tool.
424 void ShowNPoints_Tools::CreateExpandedSurface()
427 //Set Input to 0 as this function should only be executed manually but still update its children.
431 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
432 wsp->StopAutoAddPoints();
433 wsp->StopTrackPoint();
434 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
436 //Set Input to 0 as this function should only be executed manually but still update its children.
439 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
440 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
441 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
443 wsp->DeleteAllPoints_();
446 for(int i = 0; i < (int)lstX.size(); i++){
447 centroid[0] += lstX[i];
448 centroid[1] += lstY[i];
449 centroid[2] += lstZ[i];
451 centroid[0] /= lstX.size();
452 centroid[1] /= lstX.size();
453 centroid[2] /= lstX.size();
458 for(int i = 0; i < (int)lstX.size(); i++){
459 dV[0] = lstX[i] - centroid[0];
460 dV[1] = lstY[i] - centroid[1];
461 dV[2] = lstZ[i] - centroid[2];
462 vtkMath::Normalize(dV);
464 p[0] = lstX[i] + 4*dV[0];
465 p[1] = lstY[i] + 4*dV[1];
466 p[2] = lstZ[i] + 4*dV[2];
467 wsp->AddPoint(p[0] ,p[1], p[2],"");
469 std::vector<double> outData = {centroid[0], centroid[1], centroid[2]};
470 bbSetOutputOut(outData);
473 printf("PG ShowNPoints_Tools::CreateExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
477 wsp->UndoRedo_SaveCollection();
481 * Creates a cutting surface with 3 groups of points. This surface can have its area adjusted
482 * (Increase or decrease distance from points to centroid of spline or distance between splines)
483 * The centroid and normal is set as the Output, to be used by the expanding tools.
485 void ShowNPoints_Tools::CreateWideExpandedSurface()
488 //Set Input to 0 as this function is only used by the popup menu
492 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
493 wsp->StopAutoAddPoints();
494 wsp->StopTrackPoint();
496 if((wsp->GetLstModelShowNPointsSize()==1) && (bbGetInputMesh()!=NULL ) && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0))
498 std::vector<double> lstX = wsp->GetModelShowNPoints()->GetLstPointsX();
499 std::vector<double> lstY = wsp->GetModelShowNPoints()->GetLstPointsY();
500 std::vector<double> lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ();
502 wsp->DeleteAllPoints_();
507 for(int i = 0; i < (int)lstX.size(); i++){
508 centroid[0] += lstX[i];
509 centroid[1] += lstY[i];
510 centroid[2] += lstZ[i];
512 centroid[0] /= lstX.size();
513 centroid[1] /= lstX.size();
514 centroid[2] /= lstX.size();
517 double currNormal[3];
519 for(int i = 0; i < ((int)lstX.size())-1; i++){
520 v1[0] = lstX[i] - centroid[0];
521 v1[1] = lstY[i] - centroid[1];
522 v1[2] = lstZ[i] - centroid[2];
523 v2[0] = lstX[i+1] - centroid[0];
524 v2[1] = lstY[i+1] - centroid[1];
525 v2[2] = lstZ[i+1] - centroid[2];
526 vtkMath::Cross(v1, v2, currNormal);
527 normal[0] += currNormal[0];
528 normal[1] += currNormal[1];
529 normal[2] += currNormal[2];
532 normal[0] /= (lstX.size()-1);
533 normal[1] /= (lstX.size()-1);
534 normal[2] /= (lstX.size()-1);
536 vtkMath::Normalize(normal);
540 //Add new groups on both sides from the original spline
541 for(int group = 0; group < 2; group++){
542 for(int i = 0; i < (int) lstX.size(); i++){
543 dV[0] = lstX[i] - centroid[0];
544 dV[1] = lstY[i] - centroid[1];
545 dV[2] = lstZ[i] - centroid[2];
546 vtkMath::Normalize(dV);
548 np[0] = lstX[i] + dV[0]*4 + ((normal[0]*2)*addNormal);
549 np[1] = lstY[i] + dV[1]*4 + ((normal[1]*2)*addNormal);
550 np[2] = lstZ[i] + dV[2]*4 + ((normal[2]*2)*addNormal);
551 wsp->AddPoint(np[0] ,np[1], np[2],"");
554 if(group < 1)wsp->InsertCollectionAfter_();
557 std::vector<double> outData = {centroid[0], centroid[1], centroid[2], normal[0], normal[1], normal[2]};
558 bbSetOutputOut(outData);
562 wsp->UndoRedo_SaveCollection();
565 printf("PG ShowNPoints_Tools::CreateWideExpandedSurface Warning surface not apply. groups, mesh or points invalid. need 1 group of points\n");
570 * Given a cutting surface, expand its area by moving the points outwards of the main centroid.
572 void ShowNPoints_Tools::ExpandSurfaceArea()
574 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
575 wsp->StopAutoAddPoints();
576 wsp->StopTrackPoint();
578 if((wsp->GetLstModelShowNPointsSize()==1 || wsp->GetLstModelShowNPointsSize() == 2)
579 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
580 && (bbGetInputParams().size() == 4))
582 std::vector<double> params = bbGetInputParams();
583 double direction = params[3];
584 double centroid[3] = {params[0], params[1], params[2]};
586 double dV[3], currPoint[3], mdfdPoint[3];
588 std::vector<double> modPoint;
589 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
590 for(int i = 0; i < pointsPerSpline; i++){
591 wsp->GetCollectionPoint(0, i, currPoint);
592 dV[0] = currPoint[0] - centroid[0];
593 dV[1] = currPoint[1] - centroid[1];
594 dV[2] = currPoint[2] - centroid[2];
595 vtkMath::Normalize(dV);
597 vtkMath::MultiplyScalar(dV, direction);
598 vtkMath::Add(currPoint, dV, mdfdPoint);
599 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
600 wsp->SetCollectionPoint(0, i, modPoint);
602 if(wsp->GetLstModelShowNPointsSize() == 2){
603 wsp->GetCollectionPoint(1, i, currPoint);
604 vtkMath::Add(currPoint, dV, mdfdPoint);
605 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
606 wsp->SetCollectionPoint(1, i, modPoint);
611 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");
615 wsp->UndoRedo_SaveCollection();
618 void ShowNPoints_Tools::ExpandPatch()
620 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
621 wsp->StopAutoAddPoints();
622 wsp->StopTrackPoint();
623 if((wsp->GetLstModelShowNPointsSize() == 3)
624 && (wsp->GetLstPointsX().size() == 13)
625 && (bbGetInputParams().size() == 4))
627 std::vector<double> params = bbGetInputParams();
628 double direction = params[3];
629 double centroid[3] = {params[0], params[1], params[2]};
631 std::vector<double> modPoint(3);
632 double currentPoint[3], dV[3], mdfdPoint[3];
633 for(int group = 0; group < 3; group++){
635 cout << "collection: " << group << " i: " << "0" << endl;
636 wsp->GetCollectionPoint(group, 0, currentPoint);
637 dV[0] = currentPoint[0] - centroid[0];
638 dV[1] = currentPoint[1] - centroid[1];
639 dV[2] = currentPoint[2] - centroid[2];
640 vtkMath::Normalize(dV);
641 vtkMath::MultiplyScalar(dV, direction);
642 vtkMath::Add(currentPoint, dV, mdfdPoint);
643 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
644 wsp->SetCollectionPoint(group, 0, modPoint);
645 cout << "collection: " << group << " i: " << "2" << endl;
646 wsp->GetCollectionPoint(group, 2, currentPoint);
647 dV[0] = currentPoint[0] - centroid[0];
648 dV[1] = currentPoint[1] - centroid[1];
649 dV[2] = currentPoint[2] - centroid[2];
650 vtkMath::Normalize(dV);
651 vtkMath::MultiplyScalar(dV, direction);
652 vtkMath::Add(currentPoint, dV, mdfdPoint);
653 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
654 wsp->SetCollectionPoint(group, 2, modPoint);
656 for(int i = 0; i < 5; i++){
657 wsp->GetCollectionPoint(group,i, currentPoint);
658 dV[0] = currentPoint[0] - centroid[0];
659 dV[1] = currentPoint[1] - centroid[1];
660 dV[2] = currentPoint[2] - centroid[2];
661 vtkMath::Normalize(dV);
662 vtkMath::MultiplyScalar(dV, direction);
663 vtkMath::Add(currentPoint, dV, mdfdPoint);
664 modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint));
665 cout << "collection: " << group << " i: " << i << endl;
666 wsp->SetCollectionPoint(group, i, modPoint);
671 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");
675 wsp->UndoRedo_SaveCollection();
679 * Given a cutting surface, expand the distance between the edge splines and the middle spline. making it "wider" or "thicker".
681 void ShowNPoints_Tools::WidenSurface()
683 WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
684 wsp->StopAutoAddPoints();
685 wsp->StopTrackPoint();
687 if((wsp->GetLstModelShowNPointsSize()==2)
688 && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0)
689 && (bbGetInputParams().size() == 4))
691 double direction = bbGetInputParams()[3];
692 double normal[3] = {bbGetInputParams()[0], bbGetInputParams()[1], bbGetInputParams()[2]};
693 vtkMath::MultiplyScalar(normal, direction);
695 int pointsPerSpline = wsp->GetModelShowNPoints()->GetLstPointsSize();
696 double pointSp1[3], pointSp2[3];
697 std::vector<double> modifiedPoint;
698 for(int i = 0; i < pointsPerSpline; i++){
699 wsp->GetCollectionPoint(0, i, pointSp1);
700 wsp->GetCollectionPoint(1, i, pointSp2);
701 vtkMath::Add(pointSp1, normal, pointSp1);
702 vtkMath::Subtract(pointSp2, normal, pointSp2);
703 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp1), std::end(pointSp1));
704 wsp->SetCollectionPoint(0, i, modifiedPoint);
705 modifiedPoint.insert(modifiedPoint.begin(), std::begin(pointSp2), std::end(pointSp2));
706 wsp->SetCollectionPoint(1, i, modifiedPoint);
710 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");
714 wsp->UndoRedo_SaveCollection();
717 // 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)
719 void ShowNPoints_Tools::Process()
722 // THE MAIN PROCESSING METHOD BODY
723 // Here we simply set the input 'In' value to the output 'Out'
724 // And print out the output value
725 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
726 // void bbSet{Input|Output}NAME(const TYPE&)
727 // const TYPE& bbGet{Input|Output}NAME() const
729 // * NAME is the name of the input/output
730 // (the one provided in the attribute 'name' of the tag 'input')
731 // * TYPE is the C++ type of the input/output
732 // (the one provided in the attribute 'type' of the tag 'input')
734 // bbSetOutputOut( bbGetInputIn() );
735 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
737 if (bbGetInputWidgetShowNPoints()!=NULL)
739 if (bbGetInputType()==1)
741 bbGetInputWidgetShowNPoints()->OnAutoAddPoints_tool();
744 if (bbGetInputType()==5)
746 bbGetInputWidgetShowNPoints()->OnAddPoint_();
748 if (bbGetInputType()==10)
750 bbGetInputWidgetShowNPoints()->OnInsertPoint_();
752 if (bbGetInputType()==20)
754 bbGetInputWidgetShowNPoints()->OnTrackPoint_tool();
756 if (bbGetInputType()==30)
758 bbGetInputWidgetShowNPoints()->OnSetPoint_();
760 if (bbGetInputType()==40)
762 bbGetInputWidgetShowNPoints()->OnErasePoint_();
764 if (bbGetInputType()==50)
766 bbGetInputWidgetShowNPoints()->OnDeleteAllPoints_();
768 if (bbGetInputType()==100)
770 bbGetInputWidgetShowNPoints()->OnInsertCollectionAfter_();
772 if (bbGetInputType()==110)
774 bbGetInputWidgetShowNPoints()->OnDeleteCollection_();
776 if (bbGetInputType()==120)
778 bbGetInputWidgetShowNPoints()->OnResetCollections_();
780 if (bbGetInputType()==200) // Create patch surface
782 InitCreatePatch_Points();
784 if (bbGetInputType()==205) // Create volume surface from points
786 InitCreateVolumeSurface_Points();
788 if (bbGetInputType()==210)
790 bbGetInputWidgetShowNPoints()->OnInvertLstPoints_();
792 if(bbGetInputType()==220)
796 if(bbGetInputType()==300)
798 CreateExpandedSurface();
800 if(bbGetInputType()==310)
802 CreateWideExpandedSurface();
804 if(bbGetInputType()==320)
808 if(bbGetInputType()==330)
812 if(bbGetInputType()==340)
816 } // if bbGetInputWidgetShowNPoints
819 // 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)
821 void ShowNPoints_Tools::bbUserSetDefaultValues()
823 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
824 // Here we initialize the input 'In' to 0
826 bbSetInputMesh(NULL);
827 bbSetInputWidgetShowNPoints(NULL);
829 std::vector<double> spc;
833 bbSetInputSpacing(spc);
836 // 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)
838 void ShowNPoints_Tools::bbUserInitializeProcessing()
840 // THE INITIALIZATION METHOD BODY :
842 // but this is where you should allocate the internal/output pointers
846 // 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)
848 void ShowNPoints_Tools::bbUserFinalizeProcessing()
850 // THE FINALIZATION METHOD BODY :
852 // but this is where you should desallocate the internal/output pointers
856 } // EO namespace bbcreaMaracasVisu