#include "bbcreaVtkPackage.h"
#include "vtkTriangleStrip.h"
+#include <vtkMath.h>
namespace bbcreaVtk
{
std::vector<int> lstIndexs = bbGetInputLstIndexs();
if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
{
- printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n");
+ printf("PG CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n");
bbSetOutputOut(NULL);
} else {
int ii,sizeSegment1,sizeSegment2;
} // for ii
iGeneral=iGeneral+sizeSegment1;
cells->InsertNextCell(triangleStrip);
- } //for LstIndexs
+ } //for LstIndexs
+
+ //false = Open
+ //true = Close
+ if(bbGetInputOpenClose()){
+ CloseContourSides(lstIndexs, true);
+ }
+ else{
+ CloseOpenContourSurface(lstIndexs);
+ }
+
// vtkPolyData *polydata = vtkPolyData::New();
if (polydata!=NULL) polydata->Delete();
polydata = vtkPolyData::New();
triangle->Update();
bbSetOutputOut( clean->GetOutput() );
}// if listXYZ size
+ printf("CreateMeshFromPoints::Process: End\n");
+}
+
+void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder){
+ int sizeLstIdexes = lstIndexs.size();
+ int sizePoints = bbGetInputLstX().size();
+
+ int firstIndex, end, centroidId, numPointsFace;
+ int increment = uPointOrder?1:sizeLstIdexes;
+ double centroid[3], currentPoint[3] = {};
+
+ for(int facesIdx = 0; facesIdx < 2; facesIdx++){
+ std::fill(std::begin(centroid), std::end(centroid), 0);
+ if(facesIdx == 0){
+ firstIndex = 0;
+ numPointsFace = uPointOrder?lstIndexs[0]: sizeLstIdexes;
+ end = uPointOrder?firstIndex + numPointsFace:sizePoints - lstIndexs[sizeLstIdexes - 1] + 1;
+ }
+ else{
+ firstIndex = uPointOrder?sizePoints - lstIndexs[sizeLstIdexes-1]:lstIndexs[0] - 1;
+ numPointsFace = uPointOrder?lstIndexs[sizeLstIdexes-1]:sizeLstIdexes;
+ end = uPointOrder?firstIndex + numPointsFace:sizePoints;
+ }
+ if(numPointsFace > 1){
+ double lastPoint[3] = {};
+ CalcCentroid(centroid, firstIndex, end, increment, numPointsFace);
+ centroidId = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]);
+ vtkSmartPointer<vtkTriangleStrip> triangleStrip1 = vtkSmartPointer<vtkTriangleStrip>::New();
+ triangleStrip1->GetPointIds()->SetNumberOfIds(numPointsFace*2+1);
+ if(facesIdx == 0){
+ int initial = firstIndex;
+ int triangleIndex = 0;
+ for(int index = initial; index < end; index+=increment){
+ triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
+ if(index+increment >= end){
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+1,initial);
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+2,centroidId);
+ }
+ else{
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
+ }
+ 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);
+ if(index-increment <= initial){
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+1,triangleStripStart);
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+2,centroidId);
+ }
+ else{
+ triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
+ }
+ triangleIndex+=2;
+ }
+ cells->InsertNextCell(triangleStrip1);
+ }
+ }
+ }
+
+}
+
+void CreateMeshFromPoints::CloseOpenContourSurface(std::vector<int> lstIndexs){
+ int sizeLstIdexes = lstIndexs.size();
+ int sizeLstX = bbGetInputLstX().size();
+ bool linePointOrder = false;
+
+ if(linePointOrder){
+ CloseContourSides(lstIndexs, false);
+ CloseContourBottom(false);
+ }
+ else{
+ CloseContourSides(lstIndexs, true);
+ CloseContourBottom(true);
+ }
+
+}
+
+void CreateMeshFromPoints::CalcCentroid(double(¢roid)[3], int start, int end, int increment, int numPoints){
+ double currPoint[3] = {};
+ for(int i = start; i < end; i+=increment){
+ points->GetPoint(i, currPoint);
+ centroid[0] += currPoint[0];
+ centroid[1] += currPoint[1];
+ centroid[2] += currPoint[2];
+ }
+ centroid[0] /= numPoints;
+ centroid[1] /= numPoints;
+ centroid[2] /= numPoints;
+}
+
+void CreateMeshFromPoints::CloseContourBottom(bool uPointOrder){
+ std::vector<int> lstIndexs = bbGetInputLstIndexs();
+ int sizeLstIdexes = lstIndexs.size();
+ int sizeLstX = bbGetInputLstX().size();
+
+ vtkSmartPointer<vtkTriangleStrip> triangleStripBottom = vtkSmartPointer<vtkTriangleStrip>::New();
+ triangleStripBottom->GetPointIds()->SetNumberOfIds(sizeLstIdexes*2);
+ int triangleIndex = 0, currentId = 0, nextId = 0;
+ for(int splineIndex = 0; splineIndex < sizeLstIdexes;splineIndex++){
+ triangleStripBottom->GetPointIds()->SetId(triangleIndex, currentId);
+ nextId = uPointOrder?currentId + lstIndexs[splineIndex] - 1:sizeLstX - sizeLstIdexes + splineIndex;
+ triangleStripBottom->GetPointIds()->SetId(triangleIndex+1, nextId);
+ triangleIndex+=2;
+ currentId = uPointOrder?nextId + 1: splineIndex+1;
+ }
+ cells->InsertNextCell(triangleStripBottom);
}
//=====
// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
// Here we initialize the input 'In' to 0
// bbSetInputIn(0);
+ bbSetInputOpenClose(false);
points = NULL;
cells = NULL;
polydata = NULL;
BBTK_DECLARE_INPUT(LstY,std::vector<double>);
BBTK_DECLARE_INPUT(LstZ,std::vector<double>);
BBTK_DECLARE_INPUT(LstIndexs,std::vector<int>);
+ BBTK_DECLARE_INPUT(OpenClose, bool);
BBTK_DECLARE_OUTPUT(Out,vtkPolyData*);
BBTK_PROCESS(Process);
void Process();
vtkPolyData *polydata;
vtkCleanPolyData *clean;
vtkTriangleFilter *triangle;
+
+ void CalcCentroid(double(¢roid)[3], int start, int end, int increment, int numPoints);
+ void CloseContourBottom(bool uPointOrder);
+ void CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder);
+ void CloseOpenContourSurface(std::vector<int> lstIndexs);
//=====
// 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)
BBTK_INPUT(CreateMeshFromPoints,LstY,"List Y point",std::vector<double>,"");
BBTK_INPUT(CreateMeshFromPoints,LstZ,"List Z point",std::vector<double>,"");
BBTK_INPUT(CreateMeshFromPoints,LstIndexs,"Number of points by segment",std::vector<int>,"");
+ BBTK_INPUT(CreateMeshFromPoints,OpenClose,"(default false) Type of Contour: false=Open, true=Close",bool,"");
BBTK_OUTPUT(CreateMeshFromPoints,Out,"vtkPolyData",vtkPolyData*,"");
--- /dev/null
+//=====
+// 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)
+//=====
+#include "bbcreaVtkGlyphPolyDataNormals.h"
+#include "bbcreaVtkPackage.h"
+
+#include "vtkProperty.h"
+#include <vtkMath.h>
+
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,GlyphPolyDataNormals)
+BBTK_BLACK_BOX_IMPLEMENTATION(GlyphPolyDataNormals,bbtk::AtomicBlackBox);
+//=====
+// 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)
+//=====
+void GlyphPolyDataNormals::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+// Here we simply set the input 'In' value to the output 'Out'
+// And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+// void bbSet{Input|Output}NAME(const TYPE&)
+// const TYPE& bbGet{Input|Output}NAME() const
+// Where :
+// * NAME is the name of the input/output
+// (the one provided in the attribute 'name' of the tag 'input')
+// * TYPE is the C++ type of the input/output
+// (the one provided in the attribute 'type' of the tag 'input')
+
+
+ //Active bool Done
+ //Color vector Done
+ //Opacity 0-1 Done
+ //Mask Ratio 1-100 Done
+ //Type of Glyph 1-Arrow 2-Line
+ //size of glyph Done
+
+ if(bbGetInputIn() == NULL){
+ printf("Warnning! GlyphPolyDataNormals::Process: Missing input PolyData\n");
+ bbSetOutputOut( NULL );
+ }
+ else if(bbGetInputRenderer() == NULL){
+ printf("Warnning! GlyphPolyDataNormals::Process: Missing Renderer\n");
+ bbSetOutputOut( NULL );
+ }
+ else{
+ //Arrow Source
+ arrow->SetTipResolution(16);
+ arrow->SetTipLength(0.5);
+ arrow->SetTipRadius(0.2 * bbGetInputGlyphType());
+ arrow->Update();
+
+ //Mask Points
+ ptMask->SetInputData(bbGetInputIn());
+ ptMask->SetOnRatio(bbGetInputMaskRatio());
+ ptMask->RandomModeOn();
+ ptMask->Update();
+ //Glyph
+ glyph->SetSourceData(arrow->GetOutput());
+ glyph->SetInputData(ptMask->GetOutput());
+ glyph->Update();
+ //glyph->SetInputData(bbGetInputIn());
+ glyph->SetVectorModeToUseNormal();
+ glyph->SetScaleFactor(bbGetInputSize());
+ glyph->SetColorModeToColorByVector();
+ glyph->SetScaleModeToScaleByVector();
+ glyph->OrientOn();
+
+ //Mapper y Actor
+ normalsMapper->SetInputData(glyph->GetOutput());
+ normalsActor->SetMapper(normalsMapper);
+ normalsActor->GetProperty()->SetOpacity(bbGetInputOpacity());
+ normalsActor->GetProperty()->SetColor(bbGetInputColor()[0],
+ bbGetInputColor()[1],
+ bbGetInputColor()[2]);
+
+ if(bbGetInputRenderer() != NULL){
+ if(actorAdded && !bbGetInputActive()){
+ bbGetInputRenderer()->RemoveActor(normalsActor);
+ actorAdded = false;
+ }
+ else if(bbGetInputActive() && !actorAdded){
+ bbGetInputRenderer()->AddActor(normalsActor);
+ actorAdded = true;
+ }
+ }
+
+ bbSetOutputOut( normalsActor );
+ }
+
+}
+//=====
+// 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)
+//=====
+void GlyphPolyDataNormals::bbUserSetDefaultValues()
+{
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputIn(NULL);
+ bbSetInputOpacity(1);
+ bbSetInputActive(false);
+ bbSetInputMaskRatio(10);
+ std::vector<double> color;
+ color.push_back(0.0);
+ color.push_back(0.0);
+ color.push_back(0.5);
+ bbSetInputColor(color);
+ bbSetInputSize(10);
+ bbSetInputGlyphType(1);
+ bbSetInputRenderer(NULL);
+ bbSetOutputOut(NULL);
+ actorAdded = false;
+}
+//=====
+// 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)
+//=====
+void GlyphPolyDataNormals::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+ arrow = vtkArrowSource::New();
+ ptMask = vtkMaskPoints::New();
+ glyph = vtkGlyph3D::New();
+ normalsMapper = vtkPolyDataMapper::New();
+ normalsActor = vtkActor::New();
+
+}
+//=====
+// 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)
+//=====
+void GlyphPolyDataNormals::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+ arrow->Delete();
+ ptMask->Delete();
+ glyph->Delete();
+ normalsMapper->Delete();
+ normalsActor->Delete();
+
+ arrow = NULL;
+ ptMask = NULL;
+ glyph = NULL;
+ normalsMapper = NULL;
+ normalsActor = NULL;
+}
+}
+// EO namespace bbcreaVtk
+
+
--- /dev/null
+//=====
+// 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)
+//=====
+#ifndef __bbcreaVtkGlyphPolyDataNormals_h_INCLUDED__
+#define __bbcreaVtkGlyphPolyDataNormals_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkPolyData.h"
+#include "vtkRenderer.h"
+#include "vtkProp3D.h"
+#include "vtkGlyph3D.h"
+#include "vtkArrowSource.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkActor.h"
+#include "vtkMaskPoints.h"
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT GlyphPolyDataNormals
+ :
+ public bbtk::AtomicBlackBox
+{
+ BBTK_BLACK_BOX_INTERFACE(GlyphPolyDataNormals,bbtk::AtomicBlackBox);
+//=====
+// 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)
+//=====
+ BBTK_DECLARE_INPUT(In,vtkPolyData*);
+ BBTK_DECLARE_INPUT(Opacity, double);
+ BBTK_DECLARE_INPUT(MaskRatio, int);
+ BBTK_DECLARE_INPUT(Active, bool);
+ BBTK_DECLARE_INPUT(Color, std::vector<double>);
+ BBTK_DECLARE_INPUT(Size, double);
+ BBTK_DECLARE_INPUT(GlyphType, int);
+ BBTK_DECLARE_INPUT(Renderer,vtkRenderer*);
+ BBTK_DECLARE_OUTPUT(Out,vtkProp3D*);
+ BBTK_PROCESS(Process);
+ void Process();
+
+ bool actorAdded;
+ vtkArrowSource *arrow;
+ vtkMaskPoints *ptMask;
+ vtkGlyph3D *glyph;
+ vtkPolyDataMapper *normalsMapper;
+ vtkActor *normalsActor;
+
+//=====
+// 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)
+//=====
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(GlyphPolyDataNormals,bbtk::AtomicBlackBox);
+BBTK_NAME("GlyphPolyDataNormals");
+BBTK_AUTHOR("InfoDev");
+BBTK_DESCRIPTION("No Description.");
+BBTK_CATEGORY("empty");
+BBTK_INPUT(GlyphPolyDataNormals,In,"in PolyData, must set normals beforehand",vtkPolyData*,"");
+BBTK_INPUT(GlyphPolyDataNormals,Opacity,"Opacity",double,"");
+BBTK_INPUT(GlyphPolyDataNormals,MaskRatio,"Mask Ratio: select every nth point",int,"");
+BBTK_INPUT(GlyphPolyDataNormals,Size,"Size",double,"");
+BBTK_INPUT(GlyphPolyDataNormals,Active,"Active",bool,"");
+BBTK_INPUT(GlyphPolyDataNormals,GlyphType,"Glyph type 0: Line | 1: Arrow",int,"");
+BBTK_INPUT(GlyphPolyDataNormals,Color,"Color",std::vector<double>,"");
+BBTK_INPUT(GlyphPolyDataNormals,Renderer,"Renderer",vtkRenderer*,"");
+BBTK_OUTPUT(GlyphPolyDataNormals,Out,"out vtkProp3D",vtkProp3D*,"");
+BBTK_END_DESCRIBE_BLACK_BOX(GlyphPolyDataNormals);
+//=====
+// 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)
+//=====
+}
+// EO namespace bbcreaVtk
+
+#endif // __bbcreaVtkGlyphPolyDataNormals_h_INCLUDED__
+