#include "bbcreaVtkPackage.h"
#include "vtkTriangleStrip.h"
+#include "vtkTriangle.h"
#include <vtkMath.h>
namespace bbcreaVtk
std::vector<double> lstY = bbGetInputLstY();
std::vector<double> lstZ = bbGetInputLstZ();
std::vector<int> lstIndexs = bbGetInputLstIndexs();
- if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
+ if ( (lstIndexs.size()<1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
{
printf("Warning! CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n");
bbSetOutputOut(NULL);
triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
iSeg1++;
iSeg2++;
- if (iSeg1>=maxSegment1) { iSeg1=maxSegment1-1; }
- if (iSeg2>=maxSegment2) { iSeg2=maxSegment2-1; }
+ if (iSeg1>=maxSegment1) { iSeg1=maxSegment1-1; }
+ if (iSeg2>=maxSegment2) { iSeg2=maxSegment2-1; }
} // for ii
iGeneral=iGeneral+sizeSegment1;
cells->InsertNextCell(triangleStrip);
} //for LstIndexs
- int lastId1 = lstIndexs[0]-1;
- int lastId2 = sizeLstX - 1;
- int firstId2 = sizeLstX - lstIndexs[sizeLstIdexes - 1];
- bool face1open = lstX[0] != lstX[lastId1] && lstY[0] != lstY[lastId1] && lstZ[0] != lstZ[lastId1];
- bool face2open = lstX[firstId2] != lstX[lastId2] && lstY[firstId2] != lstY[lastId2] && lstZ[firstId2] != lstZ[lastId2];
-
if(bbGetInputCloseSurface())
- {
+ {
+ int lastId1 = lstIndexs[0]-1;
+ int lastId2 = sizeLstX - 1;
+ int firstId2 = sizeLstX - lstIndexs[sizeLstIdexes - 1];
+ bool face1open = std::fabs(lstX[0] - lstX[lastId1]) > 0.0001 && std::fabs(lstY[0] - lstY[lastId1]) > 0.0001 && std::fabs(lstZ[0] - lstZ[lastId1]) > 0.0001;
+ bool face2open = std::fabs(lstX[firstId2] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[firstId2] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[firstId2] - lstZ[lastId2]) > 0.0001;
+
+ bool altFace1open = std::fabs(lstX[0] - lstX[firstId2]) > 0.0001 && std::fabs(lstY[0] - lstY[firstId2]) > 0.0001 && std::fabs(lstZ[0] - lstZ[firstId2]) > 0.0001;
+ bool altFace2open = std::fabs(lstX[lastId1] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[lastId1] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[lastId1] - lstZ[lastId2]) > 0.0001;
+
//false = Open Contour
//true = Closed Contour
if(!face1open && !face2open)
- {
- CloseContourSides(lstIndexs, true);
- }else{
+ {
+// isClosedCont = true;
+ CloseContourSides(lstIndexs, true, true);
+ }
+ else if(!altFace1open && !altFace2open)
+ {
+// isClosedCont = true;
+ CloseContourSides(lstIndexs, false, true);
+ }
+ else{
CloseOpenContourSurface(lstIndexs);
}
}
}// if listXYZ size
//printf("PG CreateMeshFromPoints::Process: End\n");
}
-
/**
* Closes the sides of the contour
* iterates in one way or the other, depending on the order of the points and calculated vectors.
* uPointOrder: Points are order in a U shape
* lstIndexs: number of points on each spline
*/
-void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder){
+void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder, bool isClosedCont){
int sizeLstIdexes = lstIndexs.size();
int sizePoints = bbGetInputLstX().size();
int firstIndex, end, centroidId, numPointsFace, contraryId;
int increment = uPointOrder?1:sizeLstIdexes;
double centroid[3];
-
- for(int facesIdx = 0; facesIdx < 2; facesIdx++){
+ int numProcessFaces = sizeLstIdexes > 1?2:1;
+ for(int facesIdx = 0; facesIdx < numProcessFaces; facesIdx++){
std::fill(std::begin(centroid), std::end(centroid), 0);
if(facesIdx == 0)
{
{
bool normalOrder = isPointingCorrectly(firstIndex, firstIndex+increment, centroid, contraryId);
centroidId = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]);
- vtkSmartPointer<vtkTriangleStrip> triangleStrip1 = vtkSmartPointer<vtkTriangleStrip>::New();
- triangleStrip1->GetPointIds()->SetNumberOfIds(numPointsFace*2+2);
if( normalOrder )
{
- int initial = firstIndex;
- int triangleIndex = 0;
- for(int index = initial; index < end; index+=increment){
- triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
- triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
- if(index+increment >= end){
- triangleStrip1->GetPointIds()->SetId(triangleIndex+2,initial);
- triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);
+ int initial = firstIndex;
+ for(int index = initial; index < end; index+=increment){
+ if(index+increment >= end && !isClosedCont){
+ vtkNew<vtkTriangle> triangle;
+ triangle->GetPointIds()->SetId(0, index);
+ triangle->GetPointIds()->SetId(1, initial);
+ triangle->GetPointIds()->SetId(2, centroidId);
+ cells->InsertNextCell(triangle);
+ }else if(index+increment < end){
+ vtkNew<vtkTriangle> triangle;
+ triangle->GetPointIds()->SetId(0, index);
+ triangle->GetPointIds()->SetId(1, index+increment);
+ triangle->GetPointIds()->SetId(2, centroidId);
+ cells->InsertNextCell(triangle);
}
- triangleIndex+=2;
}
- cells->InsertNextCell(triangleStrip1);
} else {
int initial = firstIndex-1;
- int triangleIndex = 0;
int triangleStripStart = end-1;
for(int index = triangleStripStart; index > initial; index-=increment){
- triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
- triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
- if(index-increment <= initial){
- triangleStrip1->GetPointIds()->SetId(triangleIndex+2,triangleStripStart);
- triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);
+ if(index-increment <= initial && !isClosedCont){
+ vtkNew<vtkTriangle> triangle;
+ triangle->GetPointIds()->SetId(0, index);
+ triangle->GetPointIds()->SetId(1, triangleStripStart);
+ triangle->GetPointIds()->SetId(2, centroidId);
+ cells->InsertNextCell(triangle);
+ }else if(index-increment > initial){
+ vtkNew<vtkTriangle> triangle;
+ triangle->GetPointIds()->SetId(0, index);
+ triangle->GetPointIds()->SetId(1, index-increment);
+ triangle->GetPointIds()->SetId(2, centroidId);
+ cells->InsertNextCell(triangle);
}
- triangleIndex+=2;
}
- cells->InsertNextCell(triangleStrip1);
}
}//if validCentroid
}//if numPointsFace
double dotCalc;
dotCalc = vtkMath::Dot(normal, contrVect);
- return dotCalc>0;
+ return dotCalc<0;
}
/**
double center[3];
double firstRadiusSum = 0;
double secondRadiusSum = 0;
- for(int i = 0; i < lstIndexs[0] && lstIndexs[0] > 3; i+=3){
- if(i+3 <= lstIndexs[0]){
+ for(int i = 0; i < lstIndexs[0] && lstIndexs[0] > 9; i+=5){
+ if(i+10 < lstIndexs[0]){
points->GetPoint(i, point1);
- points->GetPoint(i+1, point2);
- points->GetPoint(i+2, point3);
+ points->GetPoint(i+5, point2);
+ points->GetPoint(i+10, point3);
firstRadiusSum += vtkMath::Solve3PointCircle(point1, point2, point3, center);
}
}
- for(int i = 0; i < sizePoints && lstIndexs.size() > 3; i+=(lstIndexs[0]*3)){
- if(i+(3*lstIndexs[0]) <= sizePoints){
+ for(int i = 0; i < sizePoints && lstIndexs.size() > 9; i+=(lstIndexs.size()*5)){
+ if(i+(10*lstIndexs.size()) < sizePoints){
points->GetPoint(i, point1);
- points->GetPoint(i+lstIndexs[0], point2);
- points->GetPoint(i+(2*lstIndexs[0]), point3);
+ points->GetPoint(i+(5*lstIndexs.size()), point2);
+ points->GetPoint(i+(10*lstIndexs.size()), point3);
secondRadiusSum += vtkMath::Solve3PointCircle(point1, point2, point3, center);
}
}
-
+
return firstRadiusSum > secondRadiusSum;
}
*/
void CreateMeshFromPoints::CloseOpenContourSurface(std::vector<int> lstIndexs){
bool linePointOrder = CheckLinePointOrder();
- CloseContourSides(lstIndexs, !linePointOrder);
+ CloseContourSides(lstIndexs, !linePointOrder, false);
CloseContourBottom(!linePointOrder);
}
bool samePoint = true;
int splineMidPoint = numPoints/2;
bool collinear = true;
-
+
points->GetPoint(start, firstPoint);
points->GetPoint(splineMidPoint, middlePoint);
vtkMath::Subtract(middlePoint, firstPoint, vector1);
-
+
for(int i = start; i < end; i+=increment){
points->GetPoint(i, currPoint);
if(samePoint && i > start && (currPoint[0] != prevPoint[0] || currPoint[1] != prevPoint[1] || currPoint[2] != prevPoint[2])){