[vtkusers] How to construct vtkPolyData

Mark Asbach mark.asbach at post.rwth-aachen.de
Wed May 21 16:37:32 EDT 2003


Hi List,

I'm writing a procedural source object, that has to return vtkPolyData 
on its output. Several of those source objects are concatenated with a 
vtkAppendPolyData filter in my test pipeline. Now when I do an update 
on the vtkAppendPolyData object, I get a BAD_ACCESS error indicating 
that vtk tries to copy structures that are not existent or not 
initialized properly. My stack backtrace says:

> #0	0x00d9e1e0 in vtkDataSetAttributes::CopyTuple(vtkDataArray*, 
> vtkDataArray*, int, int)
> #1	0x00da34c8 in 
> vtkDataSetAttributes::CopyData(vtkDataSetAttributes::FieldList&, 
> vtkDataSetAttributes*, int, int, int)
> #2	0x014c73f8 in vtkAppendPolyData::Execute()
> #3	0x0163baec in vtkSource::ExecuteData(vtkDataObject*)
> #4	0x00e40cdc in vtkSource::UpdateData(vtkDataObject*)
> #5	0x00d96a48 in vtkDataObject::UpdateData()
> #6	0x00d96620 in vtkDataObject::Update()
> #7	0x00e3ff9c in vtkSource::Update()

This is happening on VTK 4.2.2 on a Mac OS X box. The same sources run 
without error (but probably contain the same bug hidden somewhere) on a 
Sun OS 5.9 (SunFire) machine, also on Linux (PC) and IRIX (Onyx 2), 
though I must note that all those platforms have vtk 4.0 installed.

Now, my source class does the following to generate the vtkPolyData 
(sorry for this lengthy mail):

void PolyDataSource::UpdateData (vtkDataObject * output)
{
	vtkPolyData  * polyOutput = static_cast<vtkPolyData *> (output);

	// signal beginning invocation
	this->InvokeEvent (vtkCommand::StartEvent,0);

	polyOutput->Initialize ();
	
	// allocate and copy points
	{
		vtkFloatArray  * newFloats = vtkFloatArray::New ();
		newFloats->SetNumberOfComponents (3);
		newFloats->SetNumberOfTuples     ( number of points to be generated );
		for (unsigned int i = 0; i < number of points to be generated; i++)
			newFloats->SetTuple3 (i, some values from somewhere);

		vtkPoints  * newPoints = vtkPoints::New ();
			newPoints ->Initialize ();
			newPoints ->SetData    (newFloats);
			newFloats ->Delete     ();
		polyOutput->SetPoints  (newPoints);
			newPoints ->Delete     ();
	}

	// allocate and copy attribute vectors
	{
		vtkFloatArray  * newVectors = vtkFloatArray::New ();
		newVectors->Initialize            ();
		newVectors->SetName               ("vectors");
		newVectors->SetNumberOfComponents (3);
		newVectors->SetNumberOfTuples     ( some vector attributes );
		for (unsigned int i = 0; i <  some vector attributes ; i++)
			newVectors->SetTuple3 (i,  some vector attributes );

		polyOutput->GetPointData()->SetVectors (newVectors);
		newVectors->Delete ();
	}

	// allocate and copy attribute scalars
	{
		vtkFloatArray  * newScalars = vtkFloatArray::New ();
		newScalars->Initialize            ();
		newScalars->SetName               ("scalars");
		newScalars->SetNumberOfComponents (1);
		newScalars->SetNumberOfTuples     ( some scalar attributes );
		for (unsigned int i = 0; i <  some scalar attributes ; i++)
			newScalars->SetTuple1 (i, some scalar attributes );

		polyOutput->GetPointData()->SetScalars (newScalars);
		newScalars->Delete ();
	}

	// allocate and copy vertices
	{
		cout << "copying vertices: " << polyData->numberOfVertCells << ", " 
<< polyData->verts.length () << endl;

		vtkCellArray   * newVerts   = vtkCellArray::New ();
		CORBA::Long    * verts      = newVerts->WritePointer ( 
NewNumberOfVertCells, NewArrayLength );
		for (unsigned int i = 0; i < NewArrayLength ; i++)
			verts[i] = some generated value;
		polyOutput->SetVerts  (newVerts);
		newVerts  ->Delete ();
	}

	// the same goes for lines, polygons and poly_strips
	this->InvokeEvent (vtkCommand::EndEvent, 0);
}

Did I miss something, is there any initialization that I should do?

Thanks a lot,

Mark





More information about the vtkusers mailing list