[vtkusers] Problems in Glyphing, giving me a Segmentationfault
Jan-Gerrit Drexhage
jdrexhage at wiwi.uni-bielefeld.de
Tue Nov 12 06:49:06 EST 2002
Hi there,
after making a PCA i put the values in a two-dimensional static
floatarray. This I put into a DataSet with InsertPoints. Compiling
works, though at runtime while initializing the Renderer it gives out a
SegmentationFault.
Hier is the relevant piece of code:
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkXRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkConeSource.h>
#include <vtkSphereSource.h>
#include <vtkGlyph3D.h>
#include <vtkPoints.h>
#include <vtkFloatArray.h>
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
struct SimpVec
{
float coordx;
float coordy;
float coordz;
};
#define RESOLUTION 20
#define POINTRADIUS 0.45
vector<SimpVec> vecs2;
void pcavis2(vector<SimpVec> vecs2)
{
cout << "Starting Vis" << endl;
int i;
//static float vecs2f[vecs2.size()][3];
static float (*vecs2f)[3] = new float[vecs2.size()][3];
cout << "Size of vecs2: " << vecs2.size() << endl;
//Put Vectordata into a float array
for (int j=0; j < vecs2.size(); j++){
vecs2f[j][0] = vecs2[j].coordx;
vecs2f[j][1] = vecs2[j].coordy;
vecs2f[j][2] = vecs2[j].coordz;
};
for(int k=0; k < 2; k++){
cout << "linie " << k << ": " << vecs2f[k][0] << " " << vecs2f[k][1]
<< " " << vecs2f[k][2] << endl;
};
//Create testdata and put Scalars and Points into it
vtkPolyData *testdata = vtkPolyData::New();
vtkPoints *testpoints = vtkPoints::New();
vtkFloatArray *testScalars = vtkFloatArray::New();
for (i=0; i < vecs2.size(); i++) {
testpoints->InsertPoint(i, vecs2f[i]);
cout << i << endl;
};
//for (i=0; i < vecs2f.size(); i++) testScalars->InsertTuple1(i,i);
cout << "SetPoints" << endl;
testdata->SetPoints(testpoints);
cout << "GetPointData" << endl;
testdata->GetPointData()->SetScalars(testScalars);
cout << "PolyMapper" << endl;
vtkPolyDataMapper *testMapper = vtkPolyDataMapper::New();
cout << "SetInput" << endl;
testMapper->SetInput(testdata);
cout << "Actor" << endl;
vtkActor *testActor = vtkActor::New();
cout << "SetMapper" << endl;
//Glyphing...
cout << "Glyphing" << endl;
vtkActor *spikeActor1;
vtkPolyDataMapper *spikeMapper;
vtkSphereSource *sphereG = vtkSphereSource::New();
sphereG->SetRadius(POINTRADIUS);
vtkPolyDataMapper *sphereMapperx = vtkPolyDataMapper::New();
sphereMapperx->SetInput(sphereG->GetOutput());
vtkGlyph3D *glyph = vtkGlyph3D::New();
glyph->SetInput(testdata);
glyph->SetSource(sphereG->GetOutput());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.1);
spikeMapper = vtkPolyDataMapper::New();
spikeMapper->SetInput(glyph->GetOutput());
spikeActor1 = vtkActor::New();
spikeActor1->SetMapper(spikeMapper);
cout << "Coordsystem" << endl;
vtkCylinderSource *cylinder = vtkCylinderSource::New();
cylinder->SetResolution(RESOLUTION);
cylinder->SetRadius(0.01);
cylinder->SetHeight(2);
vtkCylinderSource *cylinder2 = vtkCylinderSource::New();
cylinder2->SetResolution(RESOLUTION);
cylinder2->SetRadius(0.5);
cylinder2->SetHeight(2);
vtkCylinderSource *cylinder3 = vtkCylinderSource::New();
cylinder3->SetResolution(RESOLUTION);
cylinder3->SetRadius(1.0);
cylinder3->SetHeight(2);
vtkConeSource *cone = vtkConeSource::New();
cone->SetHeight( 0.2 );
cone->SetRadius( 0.05 );
cone->SetResolution(RESOLUTION);
vtkConeSource *cone2 = vtkConeSource::New();
cone2->SetHeight( 0.2 );
cone2->SetRadius( 0.05 );
cone2->SetResolution(RESOLUTION);
vtkConeSource *cone3 = vtkConeSource::New();
cone3->SetHeight( 0.2 );
cone3->SetRadius( 0.05 );
cone3->SetResolution(RESOLUTION);
cout << "PolyMappers" << endl;
vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();
cylinderMapper->SetInput(cylinder->GetOutput());
vtkPolyDataMapper *cylinderMapper2 = vtkPolyDataMapper::New();
cylinderMapper2->SetInput(cylinder2->GetOutput());
vtkPolyDataMapper *cylinderMapper3 = vtkPolyDataMapper::New();
cylinderMapper3->SetInput(cylinder3->GetOutput());
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInput( cone->GetOutput() );
vtkPolyDataMapper *coneMapper2 = vtkPolyDataMapper::New();
coneMapper2->SetInput( cone2->GetOutput() );
vtkPolyDataMapper *coneMapper3 = vtkPolyDataMapper::New();
coneMapper3->SetInput( cone3->GetOutput() );
cout << "Actors" << endl;
vtkActor *cylinderActor = vtkActor::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->SetPosition(0.0, 0.0, 0.0);
cylinderActor->SetOrientation(90.0, 0.0, 0.0);
vtkActor *cylinderActor2 = vtkActor::New();
cylinderActor2->SetMapper(cylinderMapper);
cylinderActor2->SetPosition(0.0, 0.0, 0.0);
cylinderActor2->SetOrientation(0.0, 90.0, 0.0);
vtkActor *cylinderActor3 = vtkActor::New();
cylinderActor3->SetMapper(cylinderMapper);
cylinderActor3->SetPosition(0.0, 0.0, 0.0);
cylinderActor3->SetOrientation(0.0, 0.0, 90.0);
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper( coneMapper );
coneActor->SetPosition(1.0 , 0.0 , 0.0);
coneActor->SetOrientation(0.0, 0.0, 0.0);
vtkActor *coneActor2 = vtkActor::New();
coneActor2->SetMapper( coneMapper );
coneActor2->SetPosition(0.0 , 1.0 , 0.0);
coneActor2->SetOrientation(90.0, 90.0, .0);
vtkActor *coneActor3 = vtkActor::New();
coneActor3->SetMapper( coneMapper );
coneActor3->SetPosition(0.0 , 0.0 , 1.0);
coneActor3->SetOrientation(0.0, -90.0, 90.0);
//StandardRenderer
cout << "Render!" << endl;
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
ren1->SetBackground(0.4,0.1,0.2);
ren1->AddActor(spikeActor1);
ren1->AddActor(cylinderActor);
ren1->AddActor(cylinderActor2);
ren1->AddActor(cylinderActor3);
ren1->AddActor(coneActor);
ren1->AddActor(coneActor2);
ren1->AddActor(coneActor3);
ren1->AddActor(testActor);
ren1->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(800, 600);
ren1->GetActiveCamera()->Zoom(1.5);
renWin->Render();
cout << "Starting iren!" << endl;
iren->Start();
cylinder->Delete();
cylinder2->Delete();
cylinder3->Delete();
cone->Delete();
cone2->Delete();
cone3->Delete();
sphereG->Delete();
cylinderMapper->Delete();
cylinderMapper2->Delete();
cylinderMapper3->Delete();
coneMapper->Delete();
coneMapper2->Delete();
coneMapper3->Delete();
cylinderActor->Delete();
cylinderActor2->Delete();
cylinderActor3->Delete();
coneActor->Delete();
coneActor2->Delete();
coneActor3->Delete();
ren1->Delete();
renWin->Delete();
iren->Delete();
}
I used the glyphing example and used vtkDataset to get the example to
work in the case I need it. Now I extended it with PCA and in my eyes I
put it in a 2-dim array as in the example to get it to work but I get
Segmentation Fault when it tries to initialize the Renderer.
Thanks for the help in advance!
Jan
More information about the vtkusers
mailing list