I assume you are referring to the Doxygen of the classes located at
http://www.vtk.org/doc/release/5.2/html/. There is some trickery in the
vtkDataArray classes like vtkDoubleArray and vtkIntArray to make them seem like
they inherit directly from vtkDataArray when in fact they really inherit from
vtkDataArrayTemplate. The Allocate method is in vtkDataArrayTemplate and is
also available in vtkDoubleArray/vtkIntArray regardless of what the
documentation tells you.
InsertNextValue is really just a convienience method that is the equivalent of
calling InsertValue with an index at the end of the array. Thus, in your
example below the two will behave the same. However, if you are preallocating
the data and computing indices anyway, I personally prefer the following code
for readability, although there should be no real impact to performance.
vtkIntArray *castkey = vtkIntArray::New();
castkey->SetName("cast_type");
castkey->SetNumberOfComponents(1);
castkey->SetNumberOfTuples(numPts);
for (int i = 0; i < L; i++)
{
for (int j = 0; j < M; j++)
{
for (int k = 0; k < N; k++)
{
int idx = i*M*N+j*N+k;
castkey->SetTupleValue(idx, &(sgn.GetData()[idx]));
}
}
}
output->GetPointData()->AddArray(castkey);
castkey->Delete(); // Does not really delete, just decrement reference count.
-Ken
On 3/30/09 7:52 PM, "shenyanwen" <[email protected]> wrote:
Hello! I just read the reference of VTK5.2, and I foud that there are no
Allocate() method in the class of vtkDoubleArray or vtkIntArray. And can I use
the InsertValue instead of InsertNextValue if I specify the actual point ID?
Can I use it like this:
vtkIntArray *castkey = vtkIntArray::New();
castkey->SetName("cast_type");
castkey->Allocate(numPts); // Allocate the memory
for (int i=0; i<L; i++) for (int j=0;j<M; j++) for (int k=0; k<N; k++)
{
int idx = i*M*N+j*N+k;
castkey->InsertValue(idx, sgn.GetData()[idx] );
}
output->GetPointData()->AddArray(castkey);
-Shenyanwen
2009/3/30 Moreland, Kenneth <[email protected]>
InsertNextValue will work just fine so long as you are careful about inserting
all the components for each tuple. Most of the time I would recommend using
InsertNextTupleValue instead. However, in either case before filling the array
I recommend calling Allocate first so that the memory will already be
allocated. This will make InsertNextValue more efficient because it will not
have to reallocate the array. Alternatively, you can call
SetNumberOfComponents and then SetNumberOfTuples and then call SetTupleValue.
The choice between the two approaches is based on how you are using them and
your own coding style.
-Ken
On 3/26/09 7:49 PM, "shenyanwen" <[email protected]
<http://[email protected]> > wrote:
Thank you !
As you described, I can add more than one type of scalars by
AddArray(type_name), and the ParaView will distinguish them by
the names I set to them. I've got it.
There is one more question. I use pressure->InsertNextValue(pressure[idx]) to
add saclar value to each point . I do not know whether this method is right or
there is another method to add the scalar value to each point !
Thanks so much!
-Seven
2009/3/27 Moreland, Kenneth <[email protected] <http://[email protected]> >
You can add more fields by simply adding them to the point data of the output
data object.
output->GetPointData()->AddArray(pressure);
Make sure that you set a name for the arrays (using the SetName method of
vtkDataArray). That is how ParaView/VTK differentiates the fields.
-Ken
On 3/23/09 12:40 AM, "shenyanwen" <[email protected]
<http://[email protected]> <http://[email protected]> > wrote:
Hi, thanks so much for your help!
I have changed my code just like what you said.
Now, I should add more than one type scalar like pressure, vol1, vol2, vol3 and
so on.
So, how can I add these scalars into my output Data?
I have already read these scalars into some variables like m_pressure[numPts],
m_vol1[numPts],m_vol[numPts] and m_vol3[numPts], and how can I add these
variables into my output Data?
Thanks so much!
--Seven
2009/3/20 Moreland, Kenneth <[email protected] <http://[email protected]>
<http://[email protected]> >
What you are using is not quite right. First, it sounds like you really want
to create a vtkImageData. This data holds a 1D, 2D, or 3D grid of points with
origin and uniform spacing on each axis. Thus, you would inherit from
vtkImageAlgorithm and cast your output to vtkImageData.
Second, the only thing you directly set in the output information is the
WHOLE_EXTENT(). You do this in RequestInformation so that the downstream
pipeline can make decisions about what to load before the data is actually
loaded. So, the first line you have below is correct, assuming you put it in
RequestInformation.
Now, you don't set UPDATE_EXTENT, you get it. Someone downstream will set this
the region of data in which it wants you to load. You don't actually have to
get this directly from the output information; you can get it from the output
object. So in RequestData, you would have code like this:
vtkImageData *output = vtkImageData::GetData(outInfo);
int *extent = output->GetUpdateExtent();
Now you can set the actual extent, spacing, origin, and data itself directly
into the data object.
output->SetExtent(extent);
output->SetOrigin(origin);
output->SetSpacing(ar);
You can then set the data either by allocating and getting scalar data through
the vtkImageData or by adding data to the image data's point data structure
(retrieved with GetPointData()). More details are in The VTK User's Guide.
-Ken
On 3/19/09 1:08 AM, "shenyanwen" <[email protected]
<http://[email protected]> <http://[email protected]>
<http://[email protected]> > wrote:
Hi, I am writing a custom reader for paraview to read my own data file which
paraview hasn't have.
I have known that the most important method is RequestInformation and
RequestData, and I just want to write a reader that can output the data type of
StructuredPoints with Scalar and some vectors.I have already use :
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
0,dim[1]-1,0,dim[1]-1,0,dim[2]-1);
outInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
0,dim[1]-1,0,dim[1]-1,0,dim[2]-1);
and:outInfo->Set(vtkDataObject::SPACING(), ar, 3);
outInfo->Set(vtkDataObject::ORIGIN(), origin, 3);
and how can I read the scalar data just like the file-format describes:
SCALAR dataName dataType numComp
LOOKUP_TABLE tableName
s0
s1
s2
...
s(n-1)
which method or function can I use to read the s0,s1,...,s(n-1) into the
variable and set to the outInfo.
Thanks so much!
**** Kenneth Moreland
*** Sandia National Laboratories
***********
*** *** *** email: [email protected] <http://[email protected]>
<http://[email protected]> <http://[email protected]>
** *** ** phone: (505) 844-8919
*** web: http://www.cs.unm.edu/~kmorel
<http://www.cs.unm.edu/%7Ekmorel> <http://www.cs.unm.edu/%7Ekmorel>
<http://www.cs.unm.edu/%7Ekmorel>
**** Kenneth Moreland
*** Sandia National Laboratories
***********
*** *** *** email: [email protected] <http://[email protected]>
<http://[email protected]>
** *** ** phone: (505) 844-8919
*** web: http://www.cs.unm.edu/~kmorel
<http://www.cs.unm.edu/%7Ekmorel> <http://www.cs.unm.edu/%7Ekmorel>
**** Kenneth Moreland
*** Sandia National Laboratories
***********
*** *** *** email: [email protected] <http://[email protected]>
** *** ** phone: (505) 844-8919
*** web: http://www.cs.unm.edu/~kmorel
<http://www.cs.unm.edu/%7Ekmorel>
**** Kenneth Moreland
*** Sandia National Laboratories
***********
*** *** *** email: [email protected]
** *** ** phone: (505) 844-8919
*** web: http://www.cs.unm.edu/~kmorel
_______________________________________________
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