[vtkusers] 3D image as N cubes

Francisco Lopez de la Franca franciscolopezdelafranca at gmail.com
Fri Jun 12 05:51:56 EDT 2015

```Sorry for so many questions, but I need to get on my project.

I've got an Octree where its DataSet contains voxels with scalar values to
0 or 1 (it comes from a binary image).

If I traverse the dataset the following way

dataset = octree->GetDataSet();

for (int z = 0; z < dims[2]; z++)
{
for (int y = 0; y < dims[1]; y++)
{
for (int x = 0; x < dims[0]; x++)
{
double* pixel =
static_cast<double*>(dataset->GetScalarPointer(x,y,z));
if ( pixel[0] != 0 )  count++;
}
}
}

then it works OK, that is, I detect how many voxels are 1's and how many
are 0's.

However, when I go through region by region, getting the vtkIds and then
the scalar value from it:

for(int j=0; j < octree->GetNumberOfLeafNodes(); j++)
{
vtkIdTypeArray* points = octree->GetPointsInRegion(j);

for(vtkIdType idx=0; idx < points->GetSize(); idx++)
{
dataset->GetPoint(idx, p); // Get the idx coordinates
x = p[0]; y = p[1]; z = p[2];

voxelValue =
static_cast<double*>(dataset->GetScalarPointer(x, y, z));
if ( voxelValue[0] != 0 ) count++;
}
}

Thank you very much for your support and patience.

then:

1. I donot know why the x, y, z coordinates are returned as double values,
e.g. instead of (1,0,0) it returns (1.07234, 0,0).
2. I donot understand why all voxel values are now 0's.

2015-06-10 13:25 GMT+02:00 Francisco Lopez de la Franca <
franciscolopezdelafranca at gmail.com>:

> Hi everybody,
> Once I retrieve the list of points (IDs) in an octree region/octant, by
> coding
>
> vtkIdTypeArray* points = octree->GetPointsInRegion(i);
>
> I'd like to know the scalar voxel value (0 or 1 since the image is binary)
> of every point in the "points" array.
> I've tried with "points->GetValue(iterator)" and with
> "points->GetTuple1()" but the result is not the expected.
>
> Please, does someone know what I should I do or what am I doing wrong?
>
> Sincerely, thank you very much.
> Regards
>
> 2015-06-09 23:49 GMT+02:00 Francisco Lopez de la Franca <
> franciscolopezdelafranca at gmail.com>:
>
>> Hi again,
>> Could anybody tell what is the difference between vtkoctreepointlocator
>> and vtkhyperoctree? I am using the former for ceating an octree from an
>> image, but i donot know which one is the best. My intention is mainly to
>> know how many points there are per octant.
>> Thank you very much.
>> My best regards.
>>
>> El miércoles, 3 de junio de 2015, Francisco Lopez de la Franca <
>> franciscolopezdelafranca at gmail.com> escribió:
>>
>>> Thanks a lot.
>>> And is there an example on how to traverse the whole octree? I mean, i
>>> would like to know how many points there are per octant.
>>> And finally, independently on the image, if i create an octree with a
>>> fixed level, will the representation be the same? I mean, the same number
>>> of octants with the same distribution independently on the image?
>>> Thank you very much.
>>> My best regards.
>>> El 03/06/2015 15:36, "Bill Lorensen" <bill.lorensen at gmail.com> escribió:
>>>
>>>> This example may help:
>>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/DataStructures/OctreeVisualize
>>>>
>>>>
>>>> On Wed, Jun 3, 2015 at 8:48 AM, Francisco Lopez de la Franca
>>>> <franciscolopezdelafranca at gmail.com> wrote:
>>>> > Hi.
>>>> > I've created an example (see below) but everything is OK except that
>>>> the
>>>> > output image is not created. I'd be very pleased if someone can help
>>>> me
>>>> > (maybe with an explanatory example or whatever).
>>>> >
>>>> >     char* filename = new char[255];
>>>> >     strcpy(filename, "nifti_image.nii");
>>>> >
>>>> >
>>>> >
>>>> >     //Create the octree
>>>> >     vtkSmartPointer<vtkOctreePointLocator> octree =
>>>> > vtkSmartPointer<vtkOctreePointLocator>::New();
>>>> >     octree->BuildLocator();
>>>> >
>>>> >     std::cout << "Number of cells in tree: " <<
>>>> > octree->GetDataSet()->GetNumberOfCells() << std::endl;
>>>> >     std::cout << "Number of points in tree: " <<
>>>> > octree->GetDataSet()->GetNumberOfPoints() << std::endl;
>>>> >
>>>> >     char* outfile = new char[255];
>>>> >     strcpy(outfile, "OcTree.vtp");
>>>> >
>>>> >     vtkSmartPointer<vtkXMLPolyDataWriter> writer =
>>>> > vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>>>> >     writer->SetInputData((vtkPolyData*) octree->GetDataSet());
>>>> >     writer->SetFileName(outfile);
>>>> >     writer->Write();
>>>> >
>>>> >
>>>> > 2015-05-29 12:40 GMT+02:00 Francisco Lopez de la Franca
>>>> > <franciscolopezdelafranca at gmail.com>:
>>>> >>
>>>> >> Hi everybody,
>>>> >> I'd like to represent a 3D image as a fixed number of cubes, I mean,
>>>> >> something like a spatial occupancy matrix in 3D.
>>>> >>
>>>> >> Could you, please, recommend me a fast way to do it or does it
>>>> exist  a
>>>> >> data structure in VTK to achieve this?
>>>> >>
>>>> >> I've found the OcTree structure but I donot know if it is valid for
>>>> this.
>>>> >>
>>>> >> Thank you very much.
>>>> >> My best regards.
>>>> >> /Francisco
>>>> >
>>>> >
>>>> >
>>>> > _______________________________________________
>>>> >
>>>> > 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
>>>> >
>>>> > http://public.kitware.com/mailman/listinfo/vtkusers
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> Unpaid intern in BillsBasement at noware dot com
>>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150612/cd5d5120/attachment.html>
```