From 3a8afa6eaa63553083bb32be8d86e3b916fda59a Mon Sep 17 00:00:00 2001 From: Ricardo A Corredor Date: Mon, 21 Jan 2013 17:24:08 +0100 Subject: [PATCH] Feature #1894 Black box to clip a polydata with a plane. NewBoxes in vtk package: PlaneClipPolyData Look into vtk/bbs/appli/examplePlaneClipPolyData.bbs for an example --- .../bbs/appli/examplePlaneClipPolyData.bbg | 51 ++++++++++++++ .../bbs/appli/examplePlaneClipPolyData.bbs | 38 +++++++++++ packages/vtk/src/bbvtkPlaneClipPolyData.cxx | 65 ++++++++++++++++++ packages/vtk/src/bbvtkPlaneClipPolyData.h | 68 +++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 packages/vtk/bbs/appli/examplePlaneClipPolyData.bbg create mode 100644 packages/vtk/bbs/appli/examplePlaneClipPolyData.bbs create mode 100644 packages/vtk/src/bbvtkPlaneClipPolyData.cxx create mode 100644 packages/vtk/src/bbvtkPlaneClipPolyData.h diff --git a/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbg b/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbg new file mode 100644 index 0000000..1bb0f12 --- /dev/null +++ b/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbg @@ -0,0 +1,51 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBG BlackBox Diagram file +# - /home/corredor/Software/CreaTools/All_Dec2012/creatools_source/bbtk/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbg +# ---------------------------------- + +APP_START +CATEGORY: +DESCRIPTION:Description ?? +AUTHOR:Author ?? +COMPLEXBOX:FALSE +COMPLEXINPUTS:0 +BOXES:4 +BOX +vtk:SphereSource:Box00 +ISEXEC:FALSE +-100.995049:79.554760:-900.000000 +-55.420049:69.554760:-900.000000 +FIN_BOX +BOX +vtk:PlaneClipPolyData:Box01 +ISEXEC:FALSE +-100.543675:49.764041:-900.000000 +-54.968675:39.764041:-900.000000 +PORT +PlaneNormal:"0 1 0" +PORT +PlaneOrigin:"0 0 0 " +FIN_BOX +BOX +vtk:PolyDataToActor:Box02 +ISEXEC:FALSE +-97.835428:23.810006:-900.000000 +-52.260428:13.810006:-900.000000 +FIN_BOX +BOX +wxvtk:Viewer3D:Box03 +ISEXEC:TRUE +-96.029930:-5.755025:-900.000000 +-35.389930:-15.755025:-900.000000 +FIN_BOX +CONNECTIONS:3 +CONNECTION +Box00:Out:Box01:PolyData +NumberOfControlPoints:0 +CONNECTION +Box01:ClippedPolyData:Box02:In +NumberOfControlPoints:0 +CONNECTION +Box02:Out:Box03:In1 +NumberOfControlPoints:0 +APP_END diff --git a/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbs b/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbs new file mode 100644 index 0000000..a5bba25 --- /dev/null +++ b/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbs @@ -0,0 +1,38 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBS BlackBox Script +# - /home/corredor/Software/CreaTools/All_Dec2012/creatools_source/bbtk/packages/vtk/bbs/appli/examplePlaneClipPolyData.bbs +# ---------------------------------- + +# BBTK GEditor Script +# ---------------------- + +include std +include itkvtk +include vtk +include wxvtk + +author "Author ??" +description "Description ??" +category "" + +new SphereSource Box00 + +new PlaneClipPolyData Box01 + set Box01.PlaneNormal "0 1 0" + set Box01.PlaneOrigin "0 0 0 " + +new PolyDataToActor Box02 + +new Viewer3D Box03 + + +connect Box00.Out Box01.PolyData + +connect Box01.ClippedPolyData Box02.In + +connect Box02.Out Box03.In1 + + + +# Complex input ports +exec Box03 diff --git a/packages/vtk/src/bbvtkPlaneClipPolyData.cxx b/packages/vtk/src/bbvtkPlaneClipPolyData.cxx new file mode 100644 index 0000000..e3432ee --- /dev/null +++ b/packages/vtk/src/bbvtkPlaneClipPolyData.cxx @@ -0,0 +1,65 @@ +//===== +// 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 "bbvtkPlaneClipPolyData.h" +#include "bbvtkPackage.h" +namespace bbvtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PlaneClipPolyData) +BBTK_BLACK_BOX_IMPLEMENTATION(PlaneClipPolyData,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 PlaneClipPolyData::Process() +{ + + //std::cout << "RaC PlaneClipPolyData::Process START"<< std::endl; + + std::vector origin = bbGetInputPlaneOrigin(); + std::vector normal = bbGetInputPlaneNormal(); + + vtkPolyData* inPolyData = bbGetInputPolyData(); + + vtkPlane* plane = vtkPlane::New(); + plane->SetOrigin(origin[0],origin[1],origin[2]); + plane->SetNormal(normal[0],normal[1],normal[2]); + + vtkClipPolyData* clipper = vtkClipPolyData::New(); + clipper->SetInputConnection(inPolyData->GetProducerPort()); + clipper->SetClipFunction(plane); + clipper->Update(); + + vtkPolyData* outPolydata = clipper->GetOutput(); + bbSetOutputClippedPolyData(outPolydata); + + // std::cout << "RaC PlaneClipPolyData::Process END "< +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace bbvtk +{ + +class bbvtk_EXPORT PlaneClipPolyData + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(PlaneClipPolyData,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(PlaneOrigin,std::vector); + BBTK_DECLARE_INPUT(PlaneNormal,std::vector); + BBTK_DECLARE_INPUT(PolyData,vtkPolyData*); + BBTK_DECLARE_OUTPUT(ClippedPolyData,vtkPolyData*); + 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(PlaneClipPolyData,bbtk::AtomicBlackBox); +BBTK_NAME("PlaneClipPolyData"); +BBTK_AUTHOR("Ricardo A Corredor"); +BBTK_DESCRIPTION("Clips a polydata with a plane determined by the origin and normal given"); +BBTK_CATEGORY(""); +BBTK_INPUT(PlaneClipPolyData,PlaneOrigin,"Cutting plane origin",std::vector,""); +BBTK_INPUT(PlaneClipPolyData,PlaneNormal,"Cutting plane normal",std::vector,""); +BBTK_INPUT(PlaneClipPolyData,PolyData,"PolyData to be clipped",vtkPolyData*,""); +BBTK_OUTPUT(PlaneClipPolyData,ClippedPolyData,"New PolyData clipped",vtkPolyData*,""); +BBTK_END_DESCRIBE_BLACK_BOX(PlaneClipPolyData); +//===== +// 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 // __bbvtkPlaneClipPolyData_h_INCLUDED__ + -- 2.47.1