From 251e090bd2628040b8f49de9de5c4cb31281f192 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 19 Aug 2013 16:06:27 +0200 Subject: [PATCH] 2113 BBTK Feature New Normal SurfaceTexture bbtk Box --- packages/vtk/src/bbvtkSurfaceTexture.cxx | 164 +++++++++++++++++++++++ packages/vtk/src/bbvtkSurfaceTexture.h | 69 ++++++++++ 2 files changed, 233 insertions(+) create mode 100644 packages/vtk/src/bbvtkSurfaceTexture.cxx create mode 100644 packages/vtk/src/bbvtkSurfaceTexture.h diff --git a/packages/vtk/src/bbvtkSurfaceTexture.cxx b/packages/vtk/src/bbvtkSurfaceTexture.cxx new file mode 100644 index 0000000..d59b7a8 --- /dev/null +++ b/packages/vtk/src/bbvtkSurfaceTexture.cxx @@ -0,0 +1,164 @@ +//===== +// 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 "bbvtkSurfaceTexture.h" +#include "bbvtkPackage.h" + +#include + + +namespace bbvtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SurfaceTexture) +BBTK_BLACK_BOX_IMPLEMENTATION(SurfaceTexture,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 SurfaceTexture::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 = " <GetSpacing(spc); + bbGetInputImage()->GetScalarRange(range); + bbGetInputImage()->GetWholeExtent(ext); + int maxX = ext[1]-ext[0]+1; + int maxY = ext[3]-ext[2]+1; + int maxZ = ext[5]-ext[4]+1; + + if (firsttime==true) + { + firsttime=false; + // Generate the colors for each point based on the color map + colors = vtkUnsignedCharArray::New(); + colors->SetNumberOfComponents(3); + colors->SetName("Colors"); + + // Create the color map + if (bbGetInputColorType()==1) + { + colorLookupTableWL = vtkWindowLevelLookupTable::New(); + colorLookupTable=colorLookupTableWL; + } else { + colorLookupTable = vtkLookupTable::New(); + } + } + colorLookupTable->SetTableRange(range[0],range[1]); + colorLookupTable->Build(); + bbGetInputMesh()->GetPointData()->SetScalars(colors); + + if (bbGetInputColorType()==1) + { + colorLookupTableWL->SetLevel( bbGetInputColorLevel() ); + colorLookupTableWL->SetWindow( bbGetInputColorWindow() ); + } + + int missingpoints = bbGetInputMesh()->GetNumberOfPoints() - colors->GetDataSize()/colors->GetNumberOfComponents(); + for(i = 0; i < missingpoints; i++) + { + colors->InsertNextTuple3(0,0,0); + } + + if (bbGetInputTransform()!=NULL) + { + bbGetInputTransform()->Update(); + } + + unsigned short gl; + double p1[3]; + double p2[3]; + double dcolor[3]; + for(i = 0; i < bbGetInputMesh()->GetNumberOfPoints(); i++) + { + if (bbGetInputTransform()!=NULL) + { + bbGetInputMesh()->GetPoint(i,p1); + bbGetInputTransform()->TransformPoint(p1,p2); + } else { + bbGetInputMesh()->GetPoint(i,p2); + } + p2[0] = p2[0]/spc[0]; + p2[1] = p2[1]/spc[1]; + p2[2] = p2[2]/spc[2]; + + if ( (p2[0]>=0) && (p2[0]=0) && (p2[1]=0) && (p2[2]GetScalarComponentAsDouble(p2[0], p2[1], p2[2],0); + } else { + gl=0; + } + colorLookupTable->GetColor(gl, dcolor); + colors->SetTuple3(i,255*dcolor[0],255*dcolor[1],255*dcolor[2]); + } // for i + bbGetInputMesh()->Modified(); + +} +//===== +// 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 SurfaceTexture::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputMesh(NULL); + bbSetInputImage(NULL); + bbSetInputColorType(0); + bbSetInputColorLevel(500); + bbSetInputColorWindow(500); + bbSetInputTransform(NULL); + + firsttime = true; + colors = NULL; + colorLookupTable = NULL; + colorLookupTableWL = 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) +//===== +void SurfaceTexture::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 SurfaceTexture::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbvtk + + diff --git a/packages/vtk/src/bbvtkSurfaceTexture.h b/packages/vtk/src/bbvtkSurfaceTexture.h new file mode 100644 index 0000000..a0b3ea4 --- /dev/null +++ b/packages/vtk/src/bbvtkSurfaceTexture.h @@ -0,0 +1,69 @@ +//===== +// 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 __bbvtkSurfaceTexture_h_INCLUDED__ +#define __bbvtkSurfaceTexture_h_INCLUDED__ +#include "bbvtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include "vtkPolyData.h" +#include "vtkImageData.h" +#include +#include +#include + +namespace bbvtk +{ + +class bbvtk_EXPORT SurfaceTexture + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(SurfaceTexture,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(Mesh,vtkPolyData*); + BBTK_DECLARE_INPUT(Image,vtkImageData*); + BBTK_DECLARE_INPUT(ColorType,int); + BBTK_DECLARE_INPUT(ColorLevel,double); + BBTK_DECLARE_INPUT(ColorWindow,double); + BBTK_DECLARE_INPUT(Transform,vtkLinearTransform*); +// BBTK_DECLARE_OUTPUT(Out,double); + BBTK_PROCESS(Process); + void Process(); + + + bool firsttime; + vtkUnsignedCharArray *colors; + vtkLookupTable *colorLookupTable; + vtkWindowLevelLookupTable *colorLookupTableWL; + +//===== +// 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(SurfaceTexture,bbtk::AtomicBlackBox); +BBTK_NAME("SurfaceTexture"); +BBTK_AUTHOR("Info-Dev"); +BBTK_DESCRIPTION("Surface texture"); +BBTK_CATEGORY(""); + BBTK_INPUT(SurfaceTexture,Mesh,"Mesh topology",vtkPolyData*,""); + BBTK_INPUT(SurfaceTexture,Image,"Image Reference",vtkImageData*,""); + BBTK_INPUT(SurfaceTexture,ColorType,"Color Type (default 0) 0 Colors, 1 ColorWindowLevel",int,""); + BBTK_INPUT(SurfaceTexture,ColorLevel,"Color Level (default 500)",double,""); + BBTK_INPUT(SurfaceTexture,ColorWindow,"ColorWindow (default 500)",double,""); + BBTK_INPUT(SurfaceTexture,Transform,"vtk Linear Transform (default NULL)",vtkLinearTransform*,""); +// BBTK_OUTPUT(SurfaceTexture,Out,"First output",double,""); + +BBTK_END_DESCRIBE_BLACK_BOX(SurfaceTexture); +//===== +// 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 bbvtk + +#endif // __bbvtkSurfaceTexture_h_INCLUDED__ + -- 2.45.0