[Paraview] can vtkImplicitPlaneWidget be used in an XML-only paraview plug-in?
Dr. Roman Grothausmann
grothausmann.roman at mh-hannover.de
Thu Aug 15 08:43:45 EDT 2013
Dear Utkarsh,
On 14/08/13 16:49, Utkarsh Ayachit wrote:
> Can you post the current XML for the filter? I think I can update that
> to add logic for the widget.
Thank You for Your reply. Well, I already got stuck trying to translate my C++
programme into XML. Below is The C++ code but I could not find an example how to
connect a series of VTK-filters in XML-syntax. Is that possible at all or should
I translate the C-code to python? The idea is to create a plug-in that does not
need compiling paraview from source.
Many thanks for Your help
Roman
______________________________________________
/////cli program to clip a voxel-dataset with a plane, as in paraview, but in a
way that the result is a voxel-dataset again. (using
vtkImplicitFunctionToImageStencil)
////parameter to specify the clipping plane can be optaitned from the paraview
widget
#include <vtkSmartPointer.h>
#include <vtkMetaImageReader.h>
#include <vtkPlane.h>
#include <vtkImplicitFunctionToImageStencil.h>
#include <vtkImageData.h>
#include <vtkImageStencil.h>
#include <vtkImageMask.h>
#include <vtkMetaImageWriter.h>
#include <vtkCallbackCommand.h>
#include <vtkCommand.h>
void ProgressFunction ( vtkObject* caller, long unsigned int eventId, void*
clientData, void* callData )
{
vtkAlgorithm *d= static_cast<vtkAlgorithm*>(caller);
fprintf(stderr, "\rFilter progress: %5.1f%%", 100.0 * d->GetProgress());
std::cerr.flush();
}
int main(int argc, char* argv[]){
if( argc != 10 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage";
std::cerr << " outputImage";
std::cerr << " origin normal";
std::cerr << " mask-value";
std::cerr << std::endl;
return EXIT_FAILURE;
}
if(!(strcasestr(argv[1],".mhd"))) {
std::cout << "The input should end with .mhd" << std::endl;
return -1;
}
if(!(strcasestr(argv[2],".mhd"))) {
std::cout << "The output should end with .mhd" << std::endl;
return -1;
}
vtkSmartPointer<vtkCallbackCommand> progressCallback =
vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(ProgressFunction);
vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName(argv[1]);
reader->Update();
vtkSmartPointer<vtkPlane> plane =
vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(atof(argv[3]), atof(argv[4]), atof(argv[5]));
plane->SetNormal(atof(argv[6]), atof(argv[7]), atof(argv[8]));
vtkSmartPointer<vtkImplicitFunctionToImageStencil> filter =
vtkSmartPointer<vtkImplicitFunctionToImageStencil>::New();
filter->SetInput(plane);
filter->SetInformationInput(reader->GetOutput());
std::cout << "Executing vtkImplicitFunctionToImageStencil..." << std::endl;
filter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
filter->Update();
std::cout << std::endl << "done." << std::endl;
//// Create an empty (3D) image of appropriate size.
vtkSmartPointer<vtkImageData> image =
vtkSmartPointer<vtkImageData>::New();
//image->SetInformationInput(reader->GetOutput());
image->SetSpacing(reader->GetOutput()->GetSpacing());
image->SetOrigin(reader->GetOutput()->GetOrigin());
image->SetExtent(reader->GetOutput()->GetExtent());
image->SetScalarTypeToUnsignedChar();
image->AllocateScalars(); // this causes blender to crash if not enough
space can be allocated
//// apply the image stencil to the empty image
vtkSmartPointer<vtkImageStencil> stencil =
vtkSmartPointer<vtkImageStencil>::New();
stencil->SetInput(image);
stencil->SetStencil(filter->GetOutput());
//stencil->ReverseStencilOn();
stencil->SetBackgroundValue(255);
std::cout << "Executing vtkImageStencil..." << std::endl;
stencil->AddObserver(vtkCommand::ProgressEvent, progressCallback);
stencil->Update();
std::cout << std::endl << "done." << std::endl;
//// mask the input image with the stencil
vtkSmartPointer<vtkImageMask> mask =
vtkSmartPointer<vtkImageMask>::New();
// mask->SetImageInputData(reader->GetOutput()); //6.0.0
// mask->SetMaskInputData(stincil->GetOutput()); //6.0.0
mask->SetImageInput(reader->GetOutput()); //5.10.1
mask->SetMaskInput(stencil->GetOutput()); //5.10.1
mask->SetMaskedOutputValue(atoi(argv[9]));
std::cout << "Executing vtkImageMask..." << std::endl;
stencil->AddObserver(vtkCommand::ProgressEvent, progressCallback);
mask->Update();
std::cout << std::endl << "done." << std::endl;
//// save the output to an mhd-file
vtkSmartPointer<vtkMetaImageWriter> writer=
vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetFileName(argv[2]);
writer->SetFileDimensionality(3);
writer->SetCompression(0);
writer->SetInputConnection(mask->GetOutputPort());
std::cout << "Writing image..." << std::endl;
stencil->AddObserver(vtkCommand::ProgressEvent, progressCallback);
writer->Write();
std::cout << std::endl << "done." << std::endl;
return EXIT_SUCCESS;
}
> On Wed, Aug 14, 2013 at 10:26 AM, Dr. Roman Grothausmann
> <grothausmann.roman at mh-hannover.de> wrote:
>> Dear mailing list members,
>>
>>
>> I managed to write c++ vtk-program that uses
>> vtkImplicitFunctionToImageStencil to "clip" image data. However one needs to
>> copy past the origin and normal coordinates of e.g. a clipping plane in
>> paraview to the cli command. Therefore I'd like to integrate this as a
>> plugin into paraview using the vtkImplicitPlaneWidget as a direct
>> interaction method.
>> Now, I wonder if there is a way to write an XML-only paraview plug-in that
>> uses e.g. a vtkImplicitPlaneWidget as input to a chain of vtk-filters? I.e.
>> would it be possible to write an XML-plug-in that would give the same
>> functionality as the paraview clip-filter or would it have to be a c++ based
>> plugin?
>> It seems there is no plug-in in the paraview XML-plugin list that uses a
>> vtkImplicitPlaneWidget nor could I find any instruction on that in the
>> plugin howto.
>>
>> Any help or hints are very much appreciated
>> Roman
>>
>>
>> On 13/08/13 13:33, Dr. Roman Grothausmann wrote:
>>>
>>> Dear mailing list members,
>>>
>>>
>>> Is there a better way (taking less render time) to clip a voxel dataset
>>> along an
>>> arbitrarily oriented plane in paraview than using the clip-filter? It
>>> works find
>>> as long as no volume rendering is chosen as the displaying method but when
>>> I
>>> change to volume rendering it takes more than a day what before took only
>>> a minute.
>>> My guess is, that the change of the type of the dataset caused by the
>>> clip-filter (output is unstructured grid) is not as efficiently rendered
>>> as
>>> vtkImage. For my purpose it would be sufficient to not clip intersected
>>> voxel
>>> themselves, just not to render those on one side of the clipping plane.
>>> Is there any way to achieve that with existing paraview or vtk-filters?
>>> If not should I use vtkImplicitFunctionToImageStencil in a plugin to
>>> create a
>>> mask image from an interactive plane-widget and then render e.g. black
>>> transparent?
>>>
>>> Any help or hints are very much appreciated
>>> Roman
>>>
>>
>> --
>> Dr. Roman Grothausmann
>>
>> Tomographie und Digitale Bildverarbeitung
>> Tomography and Digital Image Analysis
>>
>> Institut für Funktionelle und Angewandte Anatomie, OE 4120
>> Medizinische Hochschule Hannover
>> Carl-Neuberg-Str. 1
>> D-30625 Hannover
>>
>> Tel. +49 511 532-9574
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ParaView Wiki at:
>> http://paraview.org/Wiki/ParaView
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.paraview.org/mailman/listinfo/paraview
--
Dr. Roman Grothausmann
Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis
Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
D-30625 Hannover
Tel. +49 511 532-9574
More information about the ParaView
mailing list