From df4539135877e3470a9515e0baa5574ff57f18b4 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Wed, 24 Jul 2019 16:22:27 +0200 Subject: [PATCH] #3282 creaVtk Feature New Normal - PolyDataInfo --- bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx | 13 ++- .../src/bbcreaVtkPolyDataInfo.cxx | 97 +++++++++++++++++++ bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.h | 63 ++++++++++++ lib/creaVtk/vtkVectorsVisu.cpp | 68 ++++++++++--- lib/creaVtk/vtkVectorsVisu.h | 2 +- 5 files changed, 221 insertions(+), 22 deletions(-) create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.h diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx index 959c59c..3939f54 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx @@ -25,14 +25,17 @@ void GrayLevel::Process() // (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') - vtkImageData *m_image = vtkImageData::New(); - m_image = bbGetInputImage(); - int grayLevel = 0; - std::vector coord = bbGetInputCoordinate(); +// vtkImageData *m_image = vtkImageData::New(); +// m_image = bbGetInputImage(); - grayLevel = m_image->GetScalarComponentAsDouble(coord[0],coord[1],coord[2],0); + double grayLevel = -9999; + std::vector coord = bbGetInputCoordinate(); + if (bbGetInputImage()!=NULL) + { + grayLevel = bbGetInputImage()->GetScalarComponentAsDouble(coord[0],coord[1],coord[2],0); + } bbSetOutputGrayLevel(grayLevel); } diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.cxx new file mode 100644 index 0000000..5aa1f2d --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.cxx @@ -0,0 +1,97 @@ +//===== +// 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 "bbcreaVtkPolyDataInfo.h" +#include "bbcreaVtkPackage.h" +namespace bbcreaVtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PolyDataInfo) +BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataInfo,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 PolyDataInfo::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') +// bbSetOutputOut( bbGetInputIn() ); +// std::cout << "Output value = " <GetNumberOfCells() ); + bbSetOutputNumberOfLines( bbGetInputIn()->GetNumberOfLines() ); + bbSetOutputNumberOfPieces( bbGetInputIn()->GetNumberOfPieces() ); + bbSetOutputNumberOfPoints( bbGetInputIn()->GetNumberOfPoints() ); + bbSetOutputNumberOfPolys( bbGetInputIn()->GetNumberOfPolys() ); + bbSetOutputNumberOfStrips( bbGetInputIn()->GetNumberOfStrips() ); + bbSetOutputNumberOfVerts( bbGetInputIn()->GetNumberOfVerts() ); + } else { + bbSetOutputNumberOfCells(-1); + bbSetOutputNumberOfLines(-1); + bbSetOutputNumberOfPieces(-1); + bbSetOutputNumberOfPoints(-1); + bbSetOutputNumberOfPolys(-1); + bbSetOutputNumberOfStrips(-1); + bbSetOutputNumberOfVerts(-1); + }// if + +} +//===== +// 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 PolyDataInfo::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputIn(NULL); + bbSetOutputNumberOfCells(-9999); + bbSetOutputNumberOfLines(-9999); + bbSetOutputNumberOfPoints(-9999); + bbSetOutputNumberOfPieces(-9999); + bbSetOutputNumberOfPolys(-9999); + bbSetOutputNumberOfStrips(-9999); + bbSetOutputNumberOfVerts(-9999); +} +//===== +// 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 PolyDataInfo::bbUserInitializeProcessing() +{ + +// THE INITIALIZATION METHOD BODY : +// Here does nothing +// but this is where you should allocate the internal/output pointers +// if any + + +} +//===== +// 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 PolyDataInfo::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbcreaVtk + + diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.h b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.h new file mode 100644 index 0000000..b336172 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataInfo.h @@ -0,0 +1,63 @@ +//===== +// 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 __bbcreaVtkPolyDataInfo_h_INCLUDED__ +#define __bbcreaVtkPolyDataInfo_h_INCLUDED__ + +#include "bbcreaVtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include "vtkPolyData.h" + +namespace bbcreaVtk +{ + +class bbcreaVtk_EXPORT PolyDataInfo + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(PolyDataInfo,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_OUTPUT( NumberOfCells , double ); + BBTK_DECLARE_OUTPUT( NumberOfLines , double ); + BBTK_DECLARE_OUTPUT( NumberOfPoints , double ); + BBTK_DECLARE_OUTPUT( NumberOfPieces , double ); + BBTK_DECLARE_OUTPUT( NumberOfPolys , double ); + BBTK_DECLARE_OUTPUT( NumberOfStrips , double ); + BBTK_DECLARE_OUTPUT( NumberOfVerts , double ); + BBTK_PROCESS(Process); + void Process(); +//===== +// 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(PolyDataInfo,bbtk::AtomicBlackBox); + BBTK_NAME("PolyDataInfo"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + + BBTK_INPUT(PolyDataInfo,In,"vtkPolyData", vtkPolyData* ,""); + + BBTK_OUTPUT(PolyDataInfo,NumberOfCells,"Number of Cells",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfLines,"Number of Lines",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfPoints,"Number of Points",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfPieces,"Number of Pieces",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfPolys,"Number of Ploys",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfStrips,"Number of Strips",double,""); + BBTK_OUTPUT(PolyDataInfo,NumberOfVerts,"Number of Verts",double,""); + +BBTK_END_DESCRIBE_BLACK_BOX(PolyDataInfo); +//===== +// 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 // __bbcreaVtkPolyDataInfo_h_INCLUDED__ + diff --git a/lib/creaVtk/vtkVectorsVisu.cpp b/lib/creaVtk/vtkVectorsVisu.cpp index f88c650..248420a 100644 --- a/lib/creaVtk/vtkVectorsVisu.cpp +++ b/lib/creaVtk/vtkVectorsVisu.cpp @@ -35,25 +35,62 @@ #include "vtkDataObject.h" #include +#include + //------------------------------------------------------------------------------ vtkVectorsVisu::vtkVectorsVisu() :vtkVectorsTensorsVisuBase() { - _vtkarrowsource = vtkArrowSource::New(); - _vtkglyph = NULL; - _vtklinesource = vtkLineSource ::New(); - _trans = vtkTransform ::New(); + _vtkarrowsource = vtkArrowSource::New(); + _vtkglyph = NULL; + _vtklineGlyphPolyData = NULL; + _trans = vtkTransform ::New(); + double sizeCross = 0.05; + double point1[3]; double point2[3]; - point1[0]=1; - point1[1]=0; - point1[2]=0; - point2[0]=-1; - point2[1]=0; - point2[2]=0; - _vtklinesource->SetPoint1( point1 ); - _vtklinesource->SetPoint2( point2 ); + + point1[0] = 1; + point1[1] = 0; + point1[2] = 0; + point2[0] = -1; + point2[1] = 0; + point2[2] = 0; + vtkLineSource *vtklinesource1 = vtkLineSource ::New(); + vtklinesource1->SetPoint1( point1 ); + vtklinesource1->SetPoint2( point2 ); + vtklinesource1->Update(); + + point1[0] = 0; + point1[1] = sizeCross; + point1[2] = 0; + point2[0] = 0; + point2[1] = -sizeCross; + point2[2] = 0; + vtkLineSource *vtklinesource2 = vtkLineSource ::New(); + vtklinesource2->SetPoint1( point1 ); + vtklinesource2->SetPoint2( point2 ); + vtklinesource2->Update(); + + point1[0] = 0; + point1[1] = 0; + point1[2] = sizeCross; + point2[0] = 0; + point2[1] = 0; + point2[2] = -sizeCross; + vtkLineSource *vtklinesource3 = vtkLineSource ::New(); + vtklinesource3->SetPoint1( point1 ); + vtklinesource3->SetPoint2( point2 ); + vtklinesource3->Update(); + + + vtkAppendPolyData *appendPolyData = vtkAppendPolyData::New(); + appendPolyData->AddInputData( vtklinesource1->GetOutput() ); + appendPolyData->AddInputData( vtklinesource2->GetOutput() ); + appendPolyData->AddInputData( vtklinesource3->GetOutput() ); + appendPolyData->Update(); + _vtklineGlyphPolyData = appendPolyData->GetOutput(); } //------------------------------------------------------------------------------ @@ -99,10 +136,9 @@ void vtkVectorsVisu::Process() #endif } else { // source Line #if VTK_MAJOR_VERSION <= 5 - _vtkglyph->SetSource( _vtklinesource->GetOutput() ); + _vtkglyph->SetSource( _vtklineGlyphPolyData ); #else - _vtklinesource->Update(); - _vtkglyph->SetSourceData( _vtklinesource->GetOutput() ); + _vtkglyph->SetSourceData( _vtklineGlyphPolyData ); #endif } _vtkglyph->SetScaleModeToScaleByVector(); @@ -166,7 +202,7 @@ void vtkVectorsVisu::Process() // _pdm->SetColorModeToDefault(); // _pdm->SetColorModeToDirectScalars(); // NOT compile // _pdm->SetScalarModeToUsePointFieldData(); - _pdm->ImmediateModeRenderingOn(); // obsolete +// _pdm->ImmediateModeRenderingOn(); // obsolete _pdm->SetLookupTable( _externalLut ); _pdm->SelectColorArray( "angle" ); } // if _externalLut diff --git a/lib/creaVtk/vtkVectorsVisu.h b/lib/creaVtk/vtkVectorsVisu.h index ff5547a..c9a34b0 100644 --- a/lib/creaVtk/vtkVectorsVisu.h +++ b/lib/creaVtk/vtkVectorsVisu.h @@ -70,7 +70,7 @@ protected: //--------------------------------------------- private: vtkArrowSource *_vtkarrowsource; - vtkLineSource *_vtklinesource; + vtkPolyData *_vtklineGlyphPolyData; vtkGlyph3D *_vtkglyph; vtkTransform *_trans; }; -- 2.47.1