[vtkusers] vtkFastSplatter broken?
Richard Brown
richard.j.brown at live.co.uk
Wed Jan 6 06:19:02 EST 2016
Cory,
Thanks for the help. Still trying to wrap my head around it though - is there any way to splat a pre-existing vtkImageData?
Regards,
Richard
> On 05 Jan 2016, at 21:59, Cory Quammen <cory.quammen at kitware.com> wrote:
>
> Hi Richard,
>
> I think you had two problems in your code:
>
> 1). The vtkFastSplatter was auto-determining the origin and pixel
> spacing of the output image. When you moved the one point around, the
> origin was adjusted so that it was always at the location of the one
> point. This appeared in the renderer as though nothing was happening.
> You can fix this by adding a call to
>
> splatter->SetModelBounds(...)
>
> to some fixed bounding box.
>
> 2). Moving points 2-5 by 1 unit in space won't really be visible in an
> image where the voxel size is also 1 and the splat is relatively
> large. You can fix this by moving the points a further distance.
>
> Here is a modified version of your example where the points show up
> where expected:
>
> /*
> * Copyright 2004 Sandia Corporation.
> * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
> * license for use of this work by or on behalf of the
> * U.S. Government. Redistribution and use in source and binary forms, with
> * or without modification, are permitted provided that this Notice and any
> * statement of authorship are reproduced on all copies.
> */
>
> // Simple test of vtkFastSplatter
> #include "vtkImageData.h"
> #include "vtkImageShiftScale.h"
> #include "vtkFastSplatter.h"
> #include "vtkImageViewer2.h"
> #include "vtkPoints.h"
> #include "vtkPolyData.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
>
> #include "vtkSmartPointer.h"
> #define VTK_CREATE(type, name) \
>
> vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
>
> #include <math.h>
>
> const int SPLAT_IMAGE_SIZE = 100;
>
> int main(int, char *[])
> {
> // For the purposes of this example we'll build the splat image by
> // hand.
>
> VTK_CREATE(vtkImageData, SplatImage);
> SplatImage->SetDimensions(SPLAT_IMAGE_SIZE, SPLAT_IMAGE_SIZE, 1);
> SplatImage->AllocateScalars(VTK_FLOAT, 1);
>
> for (int i = 0; i < SPLAT_IMAGE_SIZE; ++i)
> {
> for (int j = 0; j < SPLAT_IMAGE_SIZE; ++j)
> {
> double xCoord = 1 - fabs( (i - SPLAT_IMAGE_SIZE/2)
> / (SPLAT_IMAGE_SIZE/2.0) );
> double yCoord = 1 - fabs( (j - SPLAT_IMAGE_SIZE/2)
> / (SPLAT_IMAGE_SIZE/2.0) );
>
> SplatImage->SetScalarComponentFromDouble(i, j, 0, 0,
> xCoord * yCoord );
> }
> }
>
> VTK_CREATE(vtkPolyData, SplatPoints);
> VTK_CREATE(vtkPoints, Points);
>
> Points->SetNumberOfPoints( 5 );
> double point[3];
>
> // Move the points further
> point[0] = 100;
> point[1] = 100;
> point[2] = 0;
> Points->SetPoint( 0, point );
>
> point[0] = 100;
> point[1] = 0;
> point[2] = 0;
> Points->SetPoint( 1, point );
>
> point[0] = 0;
> point[1] = 100;
> point[2] = 0;
> Points->SetPoint( 2, point );
>
> point[0] = 0;
> point[1] = 0;
> point[2] = 0;
> Points->SetPoint( 3, point );
>
> point[0] = 199;
> point[1] = 199;
> point[2] = 0;
> Points->SetPoint( 4, point );
>
> SplatPoints->SetPoints(Points);
>
> VTK_CREATE(vtkFastSplatter, splatter);
> splatter->SetInputData( SplatPoints );
> splatter->SetOutputDimensions( 2*SPLAT_IMAGE_SIZE,
> 2*SPLAT_IMAGE_SIZE,
> 1 );
>
> // Fix the model bounds rather than relying on vtkFastSplatter to
> calculate them
> splatter->SetModelBounds(0, 199, 0, 199, 0, 0);
> splatter->SetInputData(1, SplatImage );
>
> // The image viewers and writers are only happy with unsigned char
> // images. This will convert the floats into that format.
> VTK_CREATE(vtkImageShiftScale, resultScale);
> resultScale->SetOutputScalarTypeToUnsignedChar();
> resultScale->SetShift(0);
> resultScale->SetScale(255);
> resultScale->SetInputConnection( splatter->GetOutputPort() );
>
> splatter->Update();
> resultScale->Update();
>
> splatter->GetOutput()->Print(cout);
>
> // Set up a viewer for the image. vtkImageViewer and
> // vtkImageViewer2 are convenient wrappers around vtkActor2D,
> // vtkImageMapper, vtkRenderer, and vtkRenderWindow. All you need
> // to supply is the interactor and hooray, Bob's your uncle.
> VTK_CREATE(vtkImageViewer2, ImageViewer);
> ImageViewer->SetInputConnection( resultScale->GetOutputPort() );
> ImageViewer->SetColorLevel(127);
> ImageViewer->SetColorWindow(255);
>
> VTK_CREATE(vtkRenderWindowInteractor, iren);
> ImageViewer->SetupInteractor(iren);
>
> ImageViewer->Render();
> ImageViewer->GetRenderer()->ResetCamera();
>
> iren->Initialize();
> ImageViewer->Render();
> iren->Start();
>
> return EXIT_SUCCESS;
> }
>
> HTH,
> Cory
>
>
> On Thu, Dec 17, 2015 at 6:58 AM, mbcx9rb9 <richard.j.brown at live.co.uk> wrote:
>> Hi all,
>>
>> I was hoping to use vtkFastSplatter so I took a look at the test. However,
>> it doesn't work how I expected (or how it should, I think).
>>
>> The example places 5 splatters at various coordinates. But I can't control
>> the position of those splats. If I comment out all but the first splat and
>> then change the coordinates, it doesn't move!
>>
>> Below is the relevant code, can someone confirm that if they change point[0]
>> and point[1], nothing happens? Then, try adding in a second splat (remember
>> to change Points->SetNumberOfPoints( 1 ) to 2), changing its coordinates and
>> observe that weird things start happening...
>>
>>
>> /*
>> * Copyright 2004 Sandia Corporation.
>> * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
>> * license for use of this work by or on behalf of the
>> * U.S. Government. Redistribution and use in source and binary forms, with
>> * or without modification, are permitted provided that this Notice and any
>> * statement of authorship are reproduced on all copies.
>> */
>>
>> // Simple test of vtkFastSplatter
>>
>> #include "vtkImageData.h"
>> #include "vtkImageShiftScale.h"
>> #include "vtkFastSplatter.h"
>> #include "vtkImageViewer2.h"
>> #include "vtkPoints.h"
>> #include "vtkPolyData.h"
>> #include "vtkRenderer.h"
>> #include "vtkRenderWindow.h"
>> #include "vtkRenderWindowInteractor.h"
>>
>> #include "vtkSmartPointer.h"
>> #define VTK_CREATE(type, name) \
>> vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
>>
>> #include <math.h>
>>
>> const int SPLAT_IMAGE_SIZE = 100;
>>
>> int main(int, char *[])
>> {
>> // For the purposes of this example we'll build the splat image by
>> // hand.
>>
>> VTK_CREATE(vtkImageData, SplatImage);
>> SplatImage->SetDimensions(SPLAT_IMAGE_SIZE, SPLAT_IMAGE_SIZE, 1);
>> SplatImage->AllocateScalars(VTK_FLOAT, 1);
>>
>> for (int i = 0; i < SPLAT_IMAGE_SIZE; ++i)
>> {
>> for (int j = 0; j < SPLAT_IMAGE_SIZE; ++j)
>> {
>> double xCoord = 1 - fabs( (i - SPLAT_IMAGE_SIZE/2)
>> / (SPLAT_IMAGE_SIZE/2.0) );
>> double yCoord = 1 - fabs( (j - SPLAT_IMAGE_SIZE/2)
>> / (SPLAT_IMAGE_SIZE/2.0) );
>>
>> SplatImage->SetScalarComponentFromDouble(i, j, 0, 0,
>> xCoord * yCoord );
>> }
>> }
>>
>> VTK_CREATE(vtkPolyData, SplatPoints);
>> VTK_CREATE(vtkPoints, Points);
>>
>> Points->SetNumberOfPoints( 1 );
>> double point[3];
>>
>> point[0] = 0;
>> point[1] = 0;
>> point[2] = 0;
>> Points->SetPoint( 0, point );
>> /*
>> point[0] = 1;
>> point[1] = 0;
>> point[2] = 0;
>> Points->SetPoint( 1, point );
>>
>> point[0] = -1;
>> point[1] = 1;
>> point[2] = 0;
>> Points->SetPoint( 2, point );
>>
>> point[0] = 1;
>> point[1] = -1;
>> point[2] = 0;
>> Points->SetPoint( 3, point );
>>
>> point[0] = -1;
>> point[1] = -1;
>> point[2] = 0;
>> Points->SetPoint( 4, point );
>> */
>> SplatPoints->SetPoints(Points);
>>
>> VTK_CREATE(vtkFastSplatter, splatter);
>> splatter->SetInputData( SplatPoints );
>> splatter->SetOutputDimensions( 2*SPLAT_IMAGE_SIZE,
>> 2*SPLAT_IMAGE_SIZE,
>> 1 );
>> splatter->SetInputData(1, SplatImage );
>>
>> // The image viewers and writers are only happy with unsigned char
>> // images. This will convert the floats into that format.
>> VTK_CREATE(vtkImageShiftScale, resultScale);
>> resultScale->SetOutputScalarTypeToUnsignedChar();
>> resultScale->SetShift(0);
>> resultScale->SetScale(255);
>> resultScale->SetInputConnection( splatter->GetOutputPort() );
>>
>> splatter->Update();
>> resultScale->Update();
>>
>> // Set up a viewer for the image. vtkImageViewer and
>> // vtkImageViewer2 are convenient wrappers around vtkActor2D,
>> // vtkImageMapper, vtkRenderer, and vtkRenderWindow. All you need
>> // to supply is the interactor and hooray, Bob's your uncle.
>> VTK_CREATE(vtkImageViewer2, ImageViewer);
>> ImageViewer->SetInputConnection( resultScale->GetOutputPort() );
>> ImageViewer->SetColorLevel(127);
>> ImageViewer->SetColorWindow(255);
>>
>> VTK_CREATE(vtkRenderWindowInteractor, iren);
>> ImageViewer->SetupInteractor(iren);
>>
>> ImageViewer->Render();
>> ImageViewer->GetRenderer()->ResetCamera();
>>
>> iren->Initialize();
>> ImageViewer->Render();
>> iren->Start();
>>
>> return EXIT_SUCCESS;
>> }
>>
>>
>>
>>
>> --
>> View this message in context: http://vtk.1045678.n5.nabble.com/vtkFastSplatter-broken-tp5735566.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> 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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
More information about the vtkusers
mailing list