[vtkusers] memory problems with vtk/fltk

Alia aks01 at doc.ic.ac.uk
Wed Jul 10 11:43:39 EDT 2002


hello

I have a program that reads in 3d data and displays it in an fltk
window, its been working perfectly, but when I try to substitute one
input file for another it tells me that the instruction  referenced at
that memory location cant be read.  Its not a problem with the input
files, or the way they are being opened in the program since if I rename
the working files it will still be opened.

I'm pretty stuck and would appreciate any advice or comments on this.

Running the debugger gives me the following information in the call
stack

NVOGLNT! 050925b8()
NVOGLNT! 05092800()
NTDLL! 77f82fc9()
NTDLL! 77f8c738()
NTDLL! 77f8cef7()
NTDLL! 77f86f13()
KERNEL32! 77e8a386()
OPENGL32! 6952a023()
OPENGL32! 69533415()
OPENGL32! 69533fe6()
GDI32! 77f53eb3()
Fl_Gl_Window::show() line 67 + 19 bytes
FL_CardiacViewerUI::Initialize() line 71 + 17 bytes
main(int 1, char * * 0x04f91900) line 25
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char *
0x00133dd4, int 1) line 79 + 23 bytes
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 77e97d08()


the line being referrred to here FL_CardiacViewerUI::Initialize() line
71 + 17 bytes
is simply

vtkWindow->show();

I was wondering if anyone had come up against this sort of thing before?

A copy of my code follows - I apologise in advance for the info dump.
I've rewritten it to put everything in one file but this seems to have
the effect of causing this error for any dataset.

#include "FL_CardiacViewerUI.h"
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace std;

//extern itkCardiacViewer *viewer;
//*****************************************************************
//SET QUIT TO EXIT
void quit(Fl_Widget*, void*)
{
  exit(0);
}
//*****************************************************************
//CREATE MAIN MENU AND SET BOTH ITEMS TO MEAN QUIT
Fl_Menu_Item FL_CardiacViewerUI::mainMenu[] =
{
  { "Load", 0, (Fl_Callback *)quit },
  { "Quit", 0, (Fl_Callback *)quit },
  { 0 }
};


//*****************************************
//CONSTRUCTOR FOR THE FLTK WINDOW
FL_CardiacViewerUI::FL_CardiacViewerUI()
{
}

//********************************************
//WHEN YOU INITIALISE THE FLTK WINDOW
void FL_CardiacViewerUI::Initialize()
{
	// set up main FLTK window
	Fl_Window *mainWindow = new Fl_Window(600, 630,"3D Face
Veiwer");

	// set up menubar
	{
		Fl_Menu_Bar* o = new Fl_Menu_Bar(0, 0, 600, 30);
		o->menu(mainMenu);
	}

	// set up main VTK window
	vtkWindow = new vtkFlRenderWindowInteractor(0, 35, 600, 560,
NULL);

	// we're done populating the main_window
	mainWindow->end();

	// if the main window gets resized, the vtk window should resize
with it
	mainWindow->resizable(vtkWindow);

  // these two steps are VERY IMPORTANT, you have to show() the fltk
window
  // containing the vtkFlRenderWindowInteractor, and then the
  // vtkFlRenderWindowInteractor itself
  mainWindow->show();
  vtkWindow->show();

  // NB: here we treat the vtkFlRenderWindowInteractor just like any
other
  // old vtkRenderWindowInteractor
  vtkWindow->SetRenderWindow(renWindow);

  //SetStillUpdateRate(0.0)

 }


//*****************************************
//FUNCTION TO SAVE WINDOW CONTENTS AS PPM
void FL_CardiacViewerUI::SaveWindowView()
{
  printf(" Saving window as ppm");
  w3i = vtkWindowToImageFilter::New();
  w3i->Modified();
  w3i->SetInput(renWindow);
  wx =  vtkPNMWriter::New();
  wx->SetInput(w3i->GetOutput());
  //save a single ppm image for now
  wx->SetFileName("data/aliaFROM PPM FUNCTION.ppm");
  wx->Write();
}



void FL_CardiacViewerUI::vtkStuff()
{
//*****************************************
//VTK STUFF

  // create a rendering window and renderer
  ren = vtkRenderer::New();
  renWindow = vtkRenderWindow::New();
  renWindow->AddRenderer(ren);

 // The loop from 0 to 20.. Display 20 face images one after the other.
	for (int i=1; i<=20; i++)
	{

	// create rendering pipeline
	vtkOBJReader *reader1 = vtkOBJReader::New();

	// Declare the outputstring streams (Effectively like cout, only
going to a string..).
	ostringstream osOBJ;
	ostringstream osTEX;
	ostringstream osPPM;
	//Firstly set the integer output width to four, and the
	//padding character to '0 and then write the required
	//text to the outputstreamstring.0
	//osOBJ is a weird 'stream' thing which builds up the string.
	osOBJ << "data/animation/" << setw(4) << setfill('0') << i <<
"_Surface123.obj";
	osTEX << "data/animation/" << setw(4) << setfill('0') << i <<
"_Surface123.bmp";
	osPPM << "data/animation/" << setw(4) << setfill('0') << i <<
"_Surface123.ppm";
	// Declare a string, and give it the value of the stuff
	//  we've written to the outputstreamstring.
	string objfilename = osOBJ.str();
	string texfilename = osTEX.str();
	string ppmfilename = osPPM.str();

	// Do a bit of quick output for now...
	std::cout<< "Now handling: " << objfilename << endl;
	std::cout << "Now handling: " << texfilename << endl;

	//remember to convert string to char array for setfilename
function
	reader1->SetFileName(objfilename.c_str());

	faceMapper = vtkPolyDataMapper::New();
	faceMapper->SetInput(reader1->GetOutput());

	readerBmp1 = vtkBMPReader::New();
	readerBmp1->SetFileName(texfilename.c_str());

	atext1 = vtkTexture::New();
	atext1->SetInput(readerBmp1->GetOutput());
	atext1->InterpolateOn();

	faceActor = vtkActor::New();
	faceActor->SetMapper(faceMapper);
	faceActor->SetTexture(atext1);

	faceActor->GetProperty()->SetOpacity(1);
	faceActor->GetProperty()->SetInterpolationToGouraud();
	faceActor->GetProperty()->SetColor (215, 215, 237);
	//faceActor->GetProperty()->SetRepresentationToWireframe();
	ren->AddActor(faceActor);
	renWindow->Render();

	SaveWindowView();

	}
}






---------------------------------------------------------
To lift an autumn hair is no sign of great strength;
To see the sun and moon is no sign of sharp sight;
To hear the noise of thunder is no sign of a quick ear.
-Sun Tzu on The Art Of War
---------------------------------------------------------

.........

(its a herd of elephants seen from VERY far away)
---------------------------------------------------------





More information about the vtkusers mailing list