[vtkusers] Scalar interpolation

Brian Curtis bcurtis3 at masonlive.gmu.edu
Wed May 9 18:39:33 EDT 2012


Thanks for your help,

The following is the code that I wanted to create in the first place 
with the help from Jothy (Thank You). The values printed are weird and I 
wanted to send this to the community to help me correct any mistakes and 
so that I can gather some helpful hints from the community as to better 
practices in my code and using and understanding VTK.

Thanks,
~Brian
==============================
#include <vtkDoubleArray.h>
#include <vtkImageData.h>
#include <vtkPointData.h>
#include <vtkFloatArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkProbeFilter.h>
#include <vtkDataObjectToTable.h>
#include <vtkTable.h>
#include <vtkTableReader.h>
#include <vtkVariant.h>

int main(int, char *[]) {
     printf("This is the beggining of the file\n");

     int i;

     vtkDoubleArray* myones = vtkDoubleArray::New();
     myones->SetName("Ones Scalar Array");
     myones->InsertNextValue(1.0);
     myones->InsertNextValue(2.0);
     myones->InsertNextValue(1.0);
     myones->InsertNextValue(2.0);
     myones->InsertNextValue(1.0);
     myones->InsertNextValue(2.0);
     myones->InsertNextValue(1.0);
     myones->InsertNextValue(2.0);
     printf("Created Scalar Array\n");

     //Now Creating the dataset
     vtkImageData* griddata = vtkImageData::New();
     //griddata->SetPoints(cubepoints);
     griddata->SetDimensions(2,2,2);
     griddata->SetSpacing(2.0,2.0,2.0);
     griddata->SetOrigin(-1.0,-1.0,-1.0);
     griddata->GetPointData()->SetScalars(myones);
     printf("Set Image Data\n");

     //CREATE A LINE TO INTERPOLATE ONTO
     float line[5][3] = { {-2.0, 2.0, -2.0}, {-1.0, 1.0, -1.0},
                          {0.0, 0.0, 0.0}, {1.0, -1.0, 1.0}, {2.0, -2.0, 
2.0} };
     vtkFloatArray* lcoords = vtkFloatArray::New();
     lcoords->SetNumberOfComponents(3);
     lcoords->SetNumberOfTuples(5);
     for(i=1; i<5; i++){
         lcoords->SetTuple(i, line[i]);
     }

     vtkPoints* linepoints = vtkPoints::New();
     linepoints->SetData(lcoords);
     printf("Created linepoints\n");

     vtkPolyData* linedata = vtkPolyData::New();
     linedata->SetPoints(linepoints);
     printf("Created line data\n");

     printf("Creating Probe Filter\n");
     vtkProbeFilter* probe = vtkProbeFilter::New();
     probe->SetInput(linedata);
     probe->SetSource(griddata);
     probe->Update();

     //RETURNING RESULTS AS A VTKTABLE
     vtkDataObjectToTable* polyDataToTable = vtkDataObjectToTable::New();
     polyDataToTable->SetInputConnection(probe->GetOutputPort());
     polyDataToTable->SetFieldType(vtkDataObjectToTable::POINT_DATA);
     polyDataToTable->Update();

     //PRINT THE RESULTANT SCALAR VALUES
     vtkTable* table = polyDataToTable->GetOutput();
     int A = table->GetNumberOfRows();
     int B = table->GetNumberOfColumns();
     printf("Rows: %i Columns: %i\n",A,B);
     for(i=0; i<A; i++){
         vtkVariant test1 = table->GetValue(i,0);
         vtkVariant test2 = table->GetValue(i,1);
         printf("Row %i: (%f,%f)\n",i,test1.ToFloat(),test2.ToFloat());
     }

     printf("This is the end of the file\n");

     myones->Delete();
     griddata->Delete();
     lcoords->Delete();
     linepoints->Delete();
     linedata->Delete();
     probe->Delete();
     polyDataToTable->Delete();
     table->Delete();

     return EXIT_SUCCESS;

}
==========================



On 05/09/2012 12:21 PM, Jothybasu Selvaraj wrote:
> vtkTable::GetValue() shoudl do that.
>
>
> Jothy
>
> On Wed, May 9, 2012 at 5:11 PM, Brian Curtis 
> <bcurtis3 at masonlive.gmu.edu <mailto:bcurtis3 at masonlive.gmu.edu>> wrote:
>
>     Jothy,
>
>     Thanks for your reply.
>
>     I am interested in printing the interpolated scalar values to the
>     screen (Terminal window), how would I go about this?
>
>     ~Brian
>
>
>
>     On 05/09/2012 09:41 AM, Jothybasu Selvaraj wrote:
>>     This should help you
>>
>>     vtkSmartPointer<vtkProbeFilter>pf=
>>     vtkSmartPointer<vtkProbeFilter>::New();
>>     pf->SetInput(cube);//cube as vtkImageData
>>     pf->SetSource(line);line as vtkPolyData
>>     pf->Update();
>>
>>     //Returns the result as a vtkTable
>>     vtkSmartPointer<vtkDataObjectToTable>polyDataToTable=
>>     vtkSmartPointer<vtkDataObjectToTable>::New();
>>     polyDataToTable->SetInputConnection(pf->GetOutputPort());
>>     polyDataToTable->SetFieldType(vtkDataObjectToTable::POINT_DATA);
>>     polyDataToTable->Update();
>>
>>     Jothy
>>
>>     On Wed, May 9, 2012 at 2:17 PM, Brian Curtis
>>     <bcurtis3 at masonlive.gmu.edu <mailto:bcurtis3 at masonlive.gmu.edu>>
>>     wrote:
>>
>>         Hi,
>>
>>         I'm looking for an example that does this or a few examples
>>         that show the proper way to do this.
>>
>>         I'm not sure how to understand vtkProbeFilter from
>>         http://www.vtk.org/doc/nightly/html/classvtkProbeFilter.html
>>         and what part of it will do the work I need.
>>
>>         vtkProbeFilter->Probe requires three vtkDataSet but how do I
>>         get my points into a dataset?
>>
>>         Thanks for your help,
>>         ~Brian
>>
>>         On 05/08/2012 11:10 AM, Brian Curtis wrote:
>>
>>             Hi,
>>
>>             I am interested in creating the following simple example
>>             in order to expand off of at a later time:
>>             - Create a cube (8 points) with scalar values all set to 1
>>             - Create a line (5 points) that intersects with cube
>>             - Get scalar interpolations for the line from the cube
>>
>>             Cube pts:
>>             float pts[8][3] = { {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0},
>>                                    {-1.0, 1.0, 1.0}, {-1.0, -1.0, 1.0},
>>                                    {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0},
>>                                    {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0} };
>>             Line pts:
>>             float line[5][3] = { {-2.0, 2.0, -2.0}, {-1.0, 1.0, -1.0},
>>                                     {0.0, 0.0, 0.0}, {1.0, -1.0,
>>             1.0}, {2.0, -2.0, 2.0} };
>>
>>             I could not find a simple example to do this, and I'm not
>>             exactly sure if probefilter is the right way to go about
>>             this. What the best (and easiest) way to approach this
>>             problem?
>>
>>             Thanks,
>>             ~Brian
>>
>>             _______________________________________________
>>             Powered by www.kitware.com <http://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
>>
>>             Follow this link to subscribe/unsubscribe:
>>             http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>>
>>         _______________________________________________
>>         Powered by www.kitware.com <http://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
>>
>>         Follow this link to subscribe/unsubscribe:
>>         http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>>
>>
>>     -- 
>>     Jothy
>>
>
>
>
>
> -- 
> Jothy
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120509/538c191c/attachment.htm>


More information about the vtkusers mailing list