[vtkusers] vtkFlRenderWindowInteractor issues

Xu Zhong Hao xyzhao at singnet.com.sg
Wed Mar 10 08:19:03 EST 2004


Hi,

i am trying to ask fltk to call vtk using vtkflrenderwindowinteractor,  
i need the vtkwindow to occupied only half the fltk window, i created a  
group that is half the size of fltk window, and put  
vtkflrenderwindowinteractor as a child of the group. however, when the  
system is up, the vtk window always occupy the whole of fltk window.  
here is my code please help.

int main(int argc, char *argv[])
{
	
/ 
************************************************************************ 
************
GUI Stuff Initialization
************************************************************************ 
*************/
	
	{AR_mainWindow = new Fl_Double_Window(1022, 666, "Augmented Reality  
System");

		{ Fl_Group* o = AR_mainWindow_videoDisplay_group = new Fl_Group(35,  
45, 450, 510,"local image");
			o->box(FL_ENGRAVED_FRAME);
			o->color(57);
			o->labelfont(9);
			o->labelsize(20);
			o->labelcolor(121);
			o->end();
		}
		
		{ Fl_Group* o = skull = new Fl_Group(545, 45, 450, 510, "Virtual  
Skull");
			o->box(FL_ENGRAVED_FRAME);
			o->color(56);
			o->labelfont(9);
			o->labelsize(20);
			o->labelcolor(80);
				{ vtkFlRenderWindowInteractor* o = fl_vtk_window = new  
vtkFlRenderWindowInteractor(0, 0, 450, 510, "label");
					o->box(FL_BORDER_FRAME);
					o->color(73);
					o->selection_color(32);
					o->labeltype(FL_NORMAL_LABEL);
					o->labelfont(0);
					o->labelsize(14);
					o->labelcolor(56);
					o->align(FL_ALIGN_CENTER);
					
					o->Enable();
					//fl_vtk_window->when(FL_WHEN_RELEASE);
				}
			o->resizable(fl_vtk_window);
			o->end();
			}
		}//end of populating the fltk window
	AR_mainWindow->end();
	AR_mainWindow->resizable(fl_vtk_window);
/ 
************************************************************************ 
**********************************************************
							vtk pipeline
************************************************************************ 
**********************************************************/   
//fl_vtk_window->Initialize();
	//initialize the transformation matrix to set the skull and virtual  
endoscope
	
	double ma[16] ={0.999808,-0.00528538, 0.0188867, -0.751027,-0.0139058,  
0.488037, 0.872712, -7.20957, -0.01383, -0.872807, 0.48787,  
124.71,0,0,0,1};
	//double conem[16] = { 0.998238, 0.025045, 0.0537844, -17.5115,  
-0.00989236, 0.964105, -0.265338, 87.9089, -0.0584992, 0.264339,  
0.962654, 16.9313, 0,0,0,1};
	vtkMatrix4x4* tmatrix = vtkMatrix4x4::New();
	tmatrix->DeepCopy(ma);
	//vtkMatrix4x4* cmatrix = vtkMatrix4x4::New();
	//cmatrix->DeepCopy(conem);
	//feed the transformation matrix into the pipeline
	vtkTransform* tr = vtkTransform::New();
	tr->SetMatrix(tmatrix);
	vtkTransform* cr= vtkTransform::New();
	cr->Translate(91.0136,150,11.1121);

	//renderer, render window andinteractor initialization
	vtkRenderer *aRenderer = vtkRenderer::New();
	renWin = vtkRenderWindow::New();
	ren1= vtkRenderer::New();
	renWin->AddRenderer(aRenderer);
	//renWin->AddRenderer(ren1);
	renWin->SetSize(450,510);

	//put the render window into fltk's render window interactor
	
	fl_vtk_window->SetRenderWindow(renWin);
	
	//just like vtkrenderwindowinteractor, have to initialize it
	fl_vtk_window->Initialize();	

		
	/*now here is the real stuff
	 The following reader is used to read a series of 2D slices (images)
	 that compose the volume. The slice dimensions are set, and the
	 pixel spacing. The data Endianness must also be specified. The
      reader usese the FilePrefix in combination with the slice number to
	 construct filenames using the format FilePrefix.%d. (In this case
	 the FilePrefix is the root name of the file: quarter.)
	*/
	vtkVolume16Reader *v16 = vtkVolume16Reader::New();
     v16->SetDataDimensions(64,64);
     v16->SetDataByteOrderToLittleEndian();
     v16->SetFilePrefix ("/VTK_DATA_ROOT/Data/headsq/quarter");
     v16->SetImageRange(1, 93);
     v16->SetDataSpacing (3.2, 3.2, 1.5);
	
	/*An isosurface, or contour value of 500 is known to correspond to
	  the skin of the patient. Once generated, a vtkPolyDataNormals
	  filter is is used to create normals for smooth surface shading
	  during rendering.  The triangle stripper is used to create triangle
	  strips from the isosurface; these render much faster on may
	  systems.
	*/
	vtkContourFilter *skinExtractor = vtkContourFilter::New();
		skinExtractor->SetInput( v16->GetOutput());
		skinExtractor->SetValue(0, 500);
	vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
		skinNormals->SetInput(skinExtractor->GetOutput());
		skinNormals->SetFeatureAngle(60.0);
	vtkStripper *skinStripper = vtkStripper::New();
		skinStripper->SetInput(skinNormals->GetOutput());
	vtkTransformPolyDataFilter* skinTransform =  
vtkTransformPolyDataFilter::New();
		skinTransform->SetTransform(tr);
		skinTransform->SetInput(skinStripper->GetOutput());
	vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
		skinMapper->SetInput(skinTransform->GetOutput());
		skinMapper->ScalarVisibilityOff();
	skin = vtkActor::New();
		skin->SetMapper(skinMapper);
		skin->GetProperty()->SetDiffuseColor(1, .49, .25);
		skin->GetProperty()->SetSpecular(.3);
		skin->GetProperty()->SetSpecularPower(20);
		
	/*An isosurface, or contour value of 1150 is known to correspond to
	  filter is is used to create normals for smooth surface shading
       during rendering.  The triangle stripper is used to create  
triangle
	  strips from the isosurface; these render much faster on may
	  systems.
	  */
	vtkContourFilter *boneExtractor = vtkContourFilter::New();
		boneExtractor->SetInput((vtkDataSet *) v16->GetOutput());
		boneExtractor->SetValue(0, 1150);
	vtkPolyDataNormals *boneNormals = vtkPolyDataNormals::New();
		boneNormals->SetInput(boneExtractor->GetOutput());
			boneNormals->SetFeatureAngle(60.0);
	vtkStripper *boneStripper = vtkStripper::New();
		boneStripper->SetInput(boneNormals->GetOutput());
	vtkTransformPolyDataFilter* boneTransform =  
vtkTransformPolyDataFilter::New();
		boneTransform->SetTransform(tr);
		boneTransform->SetInput(boneStripper->GetOutput());
	vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();
		boneMapper->SetInput(boneTransform->GetOutput());
		boneMapper->ScalarVisibilityOff();
	vtkActor *bone = vtkActor::New();
		bone->SetMapper(boneMapper);
		bone->GetProperty()->SetDiffuseColor(1, 1, .9412);
		
	/*An outline provides context around the data.*/

	vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
		outlineData->SetInput((vtkDataSet *) v16->GetOutput());
	vtkTransformPolyDataFilter* outlineTransform =  
vtkTransformPolyDataFilter::New();
		outlineTransform->SetTransform(tr);
		outlineTransform->SetInput(outlineData->GetOutput());
	vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
		mapOutline->SetInput(outlineTransform->GetOutput());
		vtkActor* outline = vtkActor::New();
		outline->SetMapper(mapOutline);
		outline->GetProperty()->SetColor(0,0,0);
		
	// Now we are creating three orthogonal planes passing through the
	// volume. Each plane uses a different texture map and therefore has
	// different coloration.

	// Start by creatin a black/white lookup table.
	vtkLookupTable *bwLut = vtkLookupTable::New();
		bwLut->SetTableRange (0, 2000);
		bwLut->SetSaturationRange (0, 0);
		bwLut->SetHueRange (0, 0);
		bwLut->SetValueRange (0, 1);
		bwLut->Build();

	// Now create a lookup table that consists of the full hue circle
	// (from HSV).
	vtkLookupTable *hueLut = vtkLookupTable::New();
		hueLut->SetTableRange (0, 2000);
		hueLut->SetHueRange (0, 1);
		hueLut->SetSaturationRange (1, 1);
		hueLut->SetValueRange (1, 1);

	// Finally, create a lookup table with a single hue but having a range
	// in the saturation of the hue.
	vtkLookupTable *satLut = vtkLookupTable::New();
		satLut->SetTableRange (0, 2000);
		satLut->SetHueRange (.6, .6);
		satLut->SetSaturationRange (0, 1);
		satLut->SetValueRange (1, 1);

	// Create the first of the three planes. The filter vtkImageMapToColors
	// maps the data through the corresponding lookup table created above.  
  The
	// vtkImageActor is a type of vtkProp and conveniently displays an  
image on
	// a single quadrilateral plane. It does this using texture mapping  
and as
	// a result is quite fast. (Note: the input image has to be unsigned  
char
	// values, which the vtkImageMapToColors produces.) Note also that by
	// specifying the DisplayExtent, the pipeline requests data of this  
extent
	// and the vtkImageMapToColors only processes a slice of data.
	vtkImageMapToColors *saggitalColors = vtkImageMapToColors::New();
		saggitalColors->SetInput(v16->GetOutput());
		saggitalColors->SetLookupTable(bwLut);
	vtkImageActor *saggital = vtkImageActor::New();
		saggital->SetInput(saggitalColors->GetOutput());
		saggital->SetDisplayExtent(32,32, 0,63, 0,92);
	
	// Create the second (axial) plane of the three planes. We use the
	// same approach as before except that the extent differs.
	vtkImageMapToColors *axialColors = vtkImageMapToColors::New();
		axialColors->SetInput(v16->GetOutput());
		axialColors->SetLookupTable(bwLut);
	vtkImageActor *axial = vtkImageActor::New();
		axial->SetInput(axialColors->GetOutput());
		axial->SetDisplayExtent(0,63, 0,63, 46,46);
	
	// Create the third (coronal) plane of the three planes. We use
	// the same approach as before except that the extent differs.
	vtkImageMapToColors *coronalColors = vtkImageMapToColors::New();
		coronalColors->SetInput(v16->GetOutput());
		coronalColors->SetLookupTable(bwLut);
	vtkImageActor *coronal = vtkImageActor::New();
		coronal->SetInput(coronalColors->GetOutput());
		coronal->SetDisplayExtent(0,63, 32,32, 0,92);
		
	
	
	//now creating a cone to simulate endoscope
	
	vtkConeSource *cone = vtkConeSource::New();
		cone->SetHeight(6.0 );
		cone->SetRadius (3.0 );
		cone->SetResolution( 100);
		cone->SetCenter(0,0,0);
		cone->SetDirection(0,-1,0);
	vtkTransformPolyDataFilter* coneTransform =  
vtkTransformPolyDataFilter::New();
		coneTransform->SetTransform(cr);
		coneTransform->SetInput(cone->GetOutput());
	vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
		coneMapper->SetInput( coneTransform->GetOutput() );
	coneActor = vtkActor::New();
		coneActor->SetMapper( coneMapper );
		coneActor->GetProperty()->SetColor(1,0,0);
		
		
	// It is convenient to create an initial view of the data. The
   // FocalPoint and Position form a vector direction. Later on
   // (ResetCamera() method) this vector is used to position the camera
   // to look at the data in this direction.
   aCamera = vtkCamera::New();
     aCamera->SetViewUp (0, 0, -1);
     aCamera->SetPosition (0, 1, 0);
     aCamera->SetFocalPoint (0, 0, 0);

     aCamera->ComputeViewPlaneNormal();

	allActors= vtkAssembly::New();
	ap = vtkAssemblyPath::New();
	ap->AddNode(outline,NULL);
	ap->AddNode(skin,NULL);
	ap->AddNode(bone,NULL);

	allActors->AddPart(outline);
	allActors->AddPart(skin);
	allActors->AddPart(bone);
	aRenderer->AddActor(allActors);
	aRenderer->AddActor(coneActor);
	
	// Turn off bone for this example.
	bone->VisibilityOff();

	// Set skin to semi-transparent.
	skin->GetProperty()->SetOpacity(0.5);

	// An initial camera view is created.  The Dolly() method moves
	// the camera towards the FocalPoint, thereby enlarging the image.
	aRenderer->SetActiveCamera(aCamera);
	aRenderer->ResetCamera ();
	aCamera->Dolly(1.5);

	// Set a background color for the renderer and set the size of the
	// render window (expressed in pixels).
	aRenderer->SetBackground(1,1,1);

	// Note that when camera movement occurs (as it does in the Dolly()
	// method), the clipping planes often need adjusting. Clipping planes
	// consist of two planes: near and far along the view direction. The
	// near plane clips out objects in front of the plane; the far plane
	// clips out objects behind the plane. This way only what is drawn
	// between the planes is actually rendered.
	aRenderer->ResetCameraClippingRange ();

	
fl_vtk_window->fullscreen_off(545,45,450,510);
AR_mainWindow->show();
skull->show();
fl_vtk_window->show();
int fl_ret = Fl::run();

// NB: note that we ->Delete() the vtkFlRenderWindowInteractor
// once we do this, the rest of the vtk pipeline will really disappear
//fl_vtk_window->Delete();
// and after we've done that, we can delete the main_window

fl_vtk_window->Delete();
delete AR_mainWindow;
return fl_ret;


}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 22358 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040310/aefa8024/attachment.bin>


More information about the vtkusers mailing list