[vtkusers] vtkProgrammableSource example written in C++ or Java
da5y at k2.dion.ne.jp
da5y at k2.dion.ne.jp
Sat May 31 03:46:53 EDT 2003
Hello Jarek and vtk users
The sample source was useful for me.
Thank you for your attention.
I make my test code using vtkProgrammableSource by drawing upon
your example.
In my code, an outputdata is vtkStructuredPoints so
i extract output from GetStructuredPointsOutput.
Here is a core of my test code:
static class SphereSrc extends vtkProgrammableSource
{
void run()
{
vtkStructuredPoints source = GetStructuredPointsOutput();
source.SetDimensions(26,26,26);
source.SetOrigin(-0.5,-0.5,-0.5);
float sp = 1.0F/25.0F;
source.SetSpacing(sp, sp, sp);
vtkFloatArray scalars = new vtkFloatArray();
scalars.SetNumberOfComponents(1);
scalars.SetNumberOfTuples(26*26*26);
for (int k=0; k<26; k++)
{
double z = -0.5 + k*sp;
int kOffset = k * 26 * 26;
for (int j=0; j<26; j++)
{
double y = -0.5 + j*sp;
int jOffset = j * 26;
for (int i=0; i<26; i++)
{
double x = -0.5 + i*sp;
double s = x*x + y*y + z*z - (0.4*0.4); //(x^2 +y^2 +z^2) - R^2 //
int offset = i + jOffset + kOffset;
scalars.SetComponent(offset,0,s);
}
}
}
source.GetPointData().SetScalars(scalars);
}
}
(I attempt the whole java source file for reference.)
My question is that: When I run my class, the vtkContourFilter warns and
displays "No Data is input" , then Nothing is diplayed on the window.
I guess the reason is that the setting of vtkStructuredPoints go wrong.
I want to know the how to set the data to StructuredPoints.
Does anybody know it?
Thanks in advance
----------------------
Yoshihiko
> Yoshihiko:
>
> Here is an example in Java. vtkProgrammableSource is used to generate
> points on a cylinder. The pipeline is created in setupPipeline() method,
> the first four lines maybe of most interest to you, output is extracted
> from the source, in this case, with GetPolyDataOutput(). Here is the
> definition of the source from the example (see attached file for the
> rest):
>
> static class MyDataSource extends vtkProgrammableSource {
> void run() {
> // Get reference to output data
> vtkPolyData output = GetPolyDataOutput();
> // Create data points on a cylinder
> vtkPoints points = new vtkPoints();
> for (double z = 10D; z < (double) 100; z += 10) {
> for (double t = 0.0D;
> t < 6.2831853071795862D;
> t += 0.062831853071795868D) {
> double x = (double) 25 * Math.sin(t);
> double y = (double) 30 * Math.cos(t);
> points.InsertNextPoint(x, y, z);
> }
> }
> // Set output data
> output.SetPoints(points);
> }
> }
>
> Jarek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ProgrammableSourceTest.java
Type: application/octet-stream
Size: 3032 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030531/58fcda6a/attachment.obj>
More information about the vtkusers
mailing list