From 8ec8e2543ea61e6d9d0c852339009adb65892af4 Mon Sep 17 00:00:00 2001 From: Ricardo A Corredor Date: Wed, 16 Jan 2013 09:41:21 +0100 Subject: [PATCH] Feature #1886 Black boxes to measure lengths on images. Look into vtk/bbs/appli/exampleMeasureLength.bbs --- .../vtk/bbs/appli/exampleMeasureLength.bbg | 119 ++++++++++++++++++ .../vtk/bbs/appli/exampleMeasureLength.bbs | 76 +++++++++++ packages/vtk/src/bbvtkMeasureLength.cxx | 95 ++++++++++++++ packages/vtk/src/bbvtkMeasureLength.h | 57 +++++++++ .../vtk/src/bbvtkPointsXYZtoVTKPoints.cxx | 70 +++++++++++ packages/vtk/src/bbvtkPointsXYZtoVTKPoints.h | 57 +++++++++ 6 files changed, 474 insertions(+) create mode 100644 packages/vtk/bbs/appli/exampleMeasureLength.bbg create mode 100644 packages/vtk/bbs/appli/exampleMeasureLength.bbs create mode 100644 packages/vtk/src/bbvtkMeasureLength.cxx create mode 100644 packages/vtk/src/bbvtkMeasureLength.h create mode 100644 packages/vtk/src/bbvtkPointsXYZtoVTKPoints.cxx create mode 100644 packages/vtk/src/bbvtkPointsXYZtoVTKPoints.h diff --git a/packages/vtk/bbs/appli/exampleMeasureLength.bbg b/packages/vtk/bbs/appli/exampleMeasureLength.bbg new file mode 100644 index 0000000..f1ac03b --- /dev/null +++ b/packages/vtk/bbs/appli/exampleMeasureLength.bbg @@ -0,0 +1,119 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBG BlackBox Diagram file +# - /home/corredor/Software/CreaTools/All_Dec2012/creatools_source/bbtk/packages/vtk/bbs/appli/exampleMeasureLength.bbg +# ---------------------------------- + +APP_START +CATEGORY:example +DESCRIPTION:Evaluates the sum of the Euclidean distances among the points in the list following their order. Put some points in the image using the Points Widget and the click on Evaluate Length button. +AUTHOR:Ricardo A Corredor +COMPLEXBOX:FALSE +COMPLEXINPUTS:0 +BOXES:8 +BOX +creaMaracasVisu:ShowNPoints:Box00 +ISEXEC:TRUE +-51.309471:11.810349:-900.000000 +-2.989471:1.810349:-900.000000 +PORT +WinTitle:"Points Widget" +PORT +WinWidth:"200" +FIN_BOX +BOX +creaMaracasVisu:ViewerNV:Box02 +ISEXEC:TRUE +-26.721828:47.483487:-900.000000 +33.918172:37.483487:-900.000000 +PORT +WinTitle:"Image Viewer" +FIN_BOX +BOX +wx:CommandButton:Box03 +ISEXEC:TRUE +-128.980270:47.281481:-900.000000 +-83.405270:37.281481:-900.000000 +PORT +Label:"Evaluate length..." +PORT +WinHeight:"200" +PORT +WinTitle:"Measure Length" +PORT +WinWidth:"200" +FIN_BOX +BOX +vtk:MeasureLength:Box04 +ISEXEC:FALSE +-112.956474:-50.441103:-900.000000 +-67.381474:-60.441103:-900.000000 +FIN_BOX +BOX +vtk:PointsXYZtoVTKPoints:Box05 +ISEXEC:FALSE +-54.277786:-36.674180:-900.000000 +16.897214:-46.674180:-900.000000 +FIN_BOX +BOX +wx:OutputText:Box06 +ISEXEC:FALSE +-113.407849:-80.683196:-900.000000 +-67.832849:-90.683196:-900.000000 +FIN_BOX +BOX +vtk:MetaImageReader:Box07 +ISEXEC:FALSE +-58.531222:83.907503:-900.000000 +-12.956222:73.907503:-900.000000 +FIN_BOX +BOX +wx:FileSelector:Box08 +ISEXEC:FALSE +-57.766108:111.196570:-900.000000 +-12.191108:101.196570:-900.000000 +PORT +Message:"Select an image ..." +PORT +Title:"Select an image ..." +FIN_BOX +CONNECTIONS:13 +CONNECTION +Box02:Renderer1:Box00:Renderer +NumberOfControlPoints:0 +CONNECTION +Box02:Point:Box00:In +NumberOfControlPoints:0 +CONNECTION +Box02:BoxChange:Box00:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box00:lstPointsX:Box05:LstPointsX +NumberOfControlPoints:0 +CONNECTION +Box00:lstPointsY:Box05:LstPointsY +NumberOfControlPoints:0 +CONNECTION +Box00:lstPointsZ:Box05:LstPointsZ +NumberOfControlPoints:0 +CONNECTION +Box05:Points:Box04:Points +NumberOfControlPoints:0 +CONNECTION +Box03:BoxChange:Box06:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box04:Length:Box06:In +NumberOfControlPoints:0 +CONNECTION +Box07:Out:Box02:In +NumberOfControlPoints:0 +CONNECTION +Box07:Out:Box04:ImageData +NumberOfControlPoints:0 +CONNECTION +Box07:Out:Box00:Image +NumberOfControlPoints:0 +CONNECTION +Box08:Out:Box07:In +NumberOfControlPoints:0 +APP_END diff --git a/packages/vtk/bbs/appli/exampleMeasureLength.bbs b/packages/vtk/bbs/appli/exampleMeasureLength.bbs new file mode 100644 index 0000000..4ffc5a7 --- /dev/null +++ b/packages/vtk/bbs/appli/exampleMeasureLength.bbs @@ -0,0 +1,76 @@ +# ---------------------------------- +# - BBTKGEditor v 1.4 BBS BlackBox Script +# - /home/corredor/Software/CreaTools/All_Dec2012/creatools_source/bbtk/packages/vtk/bbs/appli/exampleMeasureLength.bbs +# ---------------------------------- + +# BBTK GEditor Script +# ---------------------- + +include std +include itkvtk +include creaMaracasVisu +include wx +include vtk + +author "Ricardo A Corredor" +description "Evaluates the sum of the Euclidean distances among the points in the list following their order. Put some points in the image using the Points Widget and the click on Evaluate Length button. " +category "example" + +new ShowNPoints Box00 + set Box00.WinTitle "Points Widget" + set Box00.WinWidth "200" + +new ViewerNV Box02 + set Box02.WinTitle "Image Viewer" + +new CommandButton Box03 + set Box03.Label "Evaluate length..." + set Box03.WinHeight "200" + set Box03.WinTitle "Measure Length" + set Box03.WinWidth "200" + +new MeasureLength Box04 + +new PointsXYZtoVTKPoints Box05 + +new OutputText Box06 + +new MetaImageReader Box07 + +new FileSelector Box08 + set Box08.Message "Select an image ..." + set Box08.Title "Select an image ..." + + +connect Box02.Renderer1 Box00.Renderer + +connect Box02.Point Box00.In + +connect Box02.BoxChange Box00.BoxExecute + +connect Box00.lstPointsX Box05.LstPointsX + +connect Box00.lstPointsY Box05.LstPointsY + +connect Box00.lstPointsZ Box05.LstPointsZ + +connect Box05.Points Box04.Points + +connect Box03.BoxChange Box06.BoxExecute + +connect Box04.Length Box06.In + +connect Box07.Out Box02.In + +connect Box07.Out Box04.ImageData + +connect Box07.Out Box00.Image + +connect Box08.Out Box07.In + + + +# Complex input ports +exec Box00 +exec Box02 +exec Box03 diff --git a/packages/vtk/src/bbvtkMeasureLength.cxx b/packages/vtk/src/bbvtkMeasureLength.cxx new file mode 100644 index 0000000..1b2a645 --- /dev/null +++ b/packages/vtk/src/bbvtkMeasureLength.cxx @@ -0,0 +1,95 @@ +//===== +// 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 "bbvtkMeasureLength.h" +#include "bbvtkPackage.h" +namespace bbvtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MeasureLength) +BBTK_BLACK_BOX_IMPLEMENTATION(MeasureLength,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 MeasureLength::Process() +{ + //std::cout << "RaC MeasureLength::Process START"<< std::endl; + + _points = bbGetInputPoints(); + _image = bbGetInputImageData(); + + double sumLength =0; + if(_image != NULL && _points->GetNumberOfPoints()>1) + { + + double spc[3]; + double origin[3]; + + _image->GetSpacing(spc); + _image->GetOrigin(origin); + + double* first; + first = _points->GetPoint(0); + + double firstWorld[3]; + firstWorld[0] = first[0]*spc[0] + origin[0]; + firstWorld[1] = first[1]*spc[1] + origin[1]; + firstWorld[2] = first[2]*spc[2] + origin[2]; + + + + for(int i = 1; i<_points->GetNumberOfPoints();i++) + { + double* second; + second = _points->GetPoint(i); + double secondWorld[3]; + secondWorld[0] = second[0]*spc[0] + origin[0]; + secondWorld[1] = second[1]*spc[1] + origin[1]; + secondWorld[2] = second[2]*spc[2] + origin[2]; + + double XFactor = secondWorld[0]-firstWorld[0]; + double YFactor = secondWorld[1]-firstWorld[1]; + double ZFactor = secondWorld[2]-firstWorld[2]; + sumLength += XFactor*XFactor + YFactor*YFactor + ZFactor*ZFactor; + + firstWorld[0] = secondWorld[0]; + firstWorld[1] = secondWorld[1]; + firstWorld[2] = secondWorld[2]; + + } + } + + bbSetOutputLength(sumLength); + + //std::cout << "RaC MeasureLength::Process END"<< std::endl; +} +//===== +// 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 MeasureLength::bbUserSetDefaultValues() +{ + bbSetOutputLength(0); +} +//===== +// 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 MeasureLength::bbUserInitializeProcessing() +{ + + + + +} +//===== +// 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 MeasureLength::bbUserFinalizeProcessing() +{ + + + +} +} +// EO namespace bbvtk + + diff --git a/packages/vtk/src/bbvtkMeasureLength.h b/packages/vtk/src/bbvtkMeasureLength.h new file mode 100644 index 0000000..d7110e9 --- /dev/null +++ b/packages/vtk/src/bbvtkMeasureLength.h @@ -0,0 +1,57 @@ +//===== +// 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 __bbvtkMeasureLength_h_INCLUDED__ +#define __bbvtkMeasureLength_h_INCLUDED__ +#include "bbvtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" + +#include "iostream" +#include "vector" +#include "math.h" + +//VTK +#include "vtkPoints.h" +#include "vtkImageData.h" + +namespace bbvtk +{ + +class bbvtk_EXPORT MeasureLength + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(MeasureLength,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(Points,vtkPoints*); + BBTK_DECLARE_INPUT(ImageData,vtkImageData*); + BBTK_DECLARE_OUTPUT(Length,double); + BBTK_PROCESS(Process); + void Process(); +private: + vtkImageData* _image; + vtkPoints* _points; +//===== +// 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(MeasureLength,bbtk::AtomicBlackBox); +BBTK_NAME("MeasureLength"); +BBTK_AUTHOR("Ricardo A Corredor"); +BBTK_DESCRIPTION("Evaluates the sum of the Euclidean distances among the points in the list following their order."); +BBTK_CATEGORY(""); +BBTK_INPUT(MeasureLength,Points,"List of points",vtkPoints*,""); +BBTK_INPUT(MeasureLength,ImageData,"Set an image if you want real lentgh (usually in mm)",vtkImageData*,""); +BBTK_OUTPUT(MeasureLength,Length,"Sum of the Euclidean distances among the points",double,""); +BBTK_END_DESCRIBE_BLACK_BOX(MeasureLength); +//===== +// 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 // __bbvtkMeasureLength_h_INCLUDED__ + diff --git a/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.cxx b/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.cxx new file mode 100644 index 0000000..0a825a2 --- /dev/null +++ b/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.cxx @@ -0,0 +1,70 @@ +//===== +// 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 "bbvtkPointsXYZtoVTKPoints.h" +#include "bbvtkPackage.h" +namespace bbvtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PointsXYZtoVTKPoints) +BBTK_BLACK_BOX_IMPLEMENTATION(PointsXYZtoVTKPoints,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 PointsXYZtoVTKPoints::Process() +{ + + //std::cout << "RaC PointsXYZtoVTKPoints::Process START"<< std::endl; + std::vector lstPointsX = bbGetInputLstPointsX(); + std::vector lstPointsY = bbGetInputLstPointsY(); + std::vector lstPointsZ = bbGetInputLstPointsZ(); + + if(_points==NULL) + _points=vtkPoints::New(); + else + _points->Reset();//CLEAR + + for (int i =0; i < lstPointsX.size(); ++i) + { + double point[3]; + point[0]=lstPointsX[i]; + point[1]=lstPointsY[i]; + point[2]=lstPointsZ[i]; + _points->InsertPoint(i,point); + } + bbSetOutputPoints(_points); + + //std::cout << "RaC PointsXYZtoVTKPoints::Process END"<< std::endl; + +} +//===== +// 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 PointsXYZtoVTKPoints::bbUserSetDefaultValues() +{ + + + +} +//===== +// 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 PointsXYZtoVTKPoints::bbUserInitializeProcessing() +{ + + + +} +//===== +// 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 PointsXYZtoVTKPoints::bbUserFinalizeProcessing() +{ + + _points->Delete(); + +} +} +// EO namespace bbvtk + + diff --git a/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.h b/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.h new file mode 100644 index 0000000..2a513ff --- /dev/null +++ b/packages/vtk/src/bbvtkPointsXYZtoVTKPoints.h @@ -0,0 +1,57 @@ +//===== +// 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 __bbvtkPointsXYZtoVTKPoints_h_INCLUDED__ +#define __bbvtkPointsXYZtoVTKPoints_h_INCLUDED__ +#include "bbvtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" + +#include "iostream" +#include "vector" + +//VTK +#include "vtkPoints.h" + +namespace bbvtk +{ + +class bbvtk_EXPORT PointsXYZtoVTKPoints + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(PointsXYZtoVTKPoints,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( LstPointsX, std::vector ); + BBTK_DECLARE_INPUT( LstPointsY, std::vector ); + BBTK_DECLARE_INPUT( LstPointsZ, std::vector ); + BBTK_DECLARE_OUTPUT(Points,vtkPoints*); + BBTK_PROCESS(Process); + void Process(); + +private: + vtkPoints* _points; +//===== +// 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(PointsXYZtoVTKPoints,bbtk::AtomicBlackBox); +BBTK_NAME("PointsXYZtoVTKPoints"); +BBTK_AUTHOR("Ricardo A Corredor"); +BBTK_DESCRIPTION("Transforms independent vectors of X, Y and Z coordinates into a vtkPoints object"); +BBTK_CATEGORY(""); +BBTK_INPUT(PointsXYZtoVTKPoints,LstPointsX,"List of points X-coordinate", std::vector ,""); +BBTK_INPUT(PointsXYZtoVTKPoints,LstPointsY,"List of points Y-coordinate", std::vector ,""); +BBTK_INPUT(PointsXYZtoVTKPoints,LstPointsZ,"List of points Z-coordinate", std::vector ,""); +BBTK_OUTPUT(PointsXYZtoVTKPoints,Points,"Points in vtkPoints",vtkPoints*,""); +BBTK_END_DESCRIBE_BLACK_BOX(PointsXYZtoVTKPoints); +//===== +// 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 // __bbvtkPointsXYZtoVTKPoints_h_INCLUDED__ + -- 2.47.1