[vtkusers] Canny - TCL to C++ conversion

Bahr, Brian BBahr at SARK.COM
Fri Oct 8 10:59:14 EDT 2004


More specifically, I am trying to write a Canny filter in C++.  I am
using the Canny.tcl file supplied by VTK at the following address...

http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Graphics/Testin
g/Tcl/Canny.tcl?root=VTK&content-type=text/plain

It seems that most of the classes and methods used in this TCL file map
directly to C++ VTK classes and methods.  I just can't quite get it
right.  Here is the C++ that I am working with...

		vtkJPEGReader* imageInReader = vtkJPEGReader::New();
		imageInReader->SetFileName("MyJPEG.jpg");
		vtkImageLuminance* il = vtkImageLuminance::New();
		il->SetInput(imageInReader->GetOutput());
		il->Update();

		vtkImageCast* ic = vtkImageCast::New();
		ic->SetOutputScalarTypeToFloat();
		ic->SetInput(il->GetOutput());
		ic->Update();

		//smooth the image
		vtkImageGaussianSmooth* pGaussian =
vtkImageGaussianSmooth::New();
		pGaussian->SetInput(ic->GetOutput());
		pGaussian->SetRadiusFactors(RFx,RFy,RFz);
		pGaussian->SetReleaseDataFlag(1);
		pGaussian->Update();

		//gradient the image
		vtkImageGradient* pGradient = vtkImageGradient::New();
		pGradient->SetInput(pGaussian->GetOutput());
		pGradient->SetDimensionality(2);
		pGradient->SetReleaseDataFlag(1);
		pGradient->Update();

		vtkImageMagnitude* pMagnitude =
vtkImageMagnitude::New();
		pMagnitude->SetInput(pGradient->GetOutput());
		pMagnitude->Update();

		vtkImageNonMaximumSuppression* pNonMax =
vtkImageNonMaximumSuppression::New();
		pNonMax->SetMagnitudeInput(pMagnitude->GetOutput());
		pNonMax->SetVectorInput(pGradient->GetOutput());
		pNonMax->SetDimensionality(2);
		pNonMax->Update();

		vtkImageConstantPad* pPad = vtkImageConstantPad::New();
		pPad->SetInput(pGradient->GetOutput());
		pPad->SetOutputNumberOfScalarComponents(3);
		pPad->SetConstant(0);
		pPad->Update();
		
		vtkImageToStructuredPoints* i2sp1 =
vtkImageToStructuredPoints::New();
		i2sp1->SetInput(pNonMax->GetOutput());
		i2sp1->SetVectorInput(pPad->GetOutput());
		i2sp1->Update();

		//link edgles
		vtkLinkEdgels* pLink = vtkLinkEdgels::New();
		pLink->SetInput((vtkImageData*)i2sp1->GetOutput());
		pLink->SetGradientThreshold(2);
		pLink->Update();

		//threshold links
		vtkThreshold* pThreshold = vtkThreshold::New();
		pThreshold->SetInput((vtkDataSet*)pLink->GetOutput());
		pThreshold->ThresholdByUpper(10);
		pThreshold->AllScalarsOff();
		pThreshold->Update();

		vtkGeometryFilter* pGeomFilter =
vtkGeometryFilter::New();
		pGeomFilter->SetInput((vtkDataSet
*)pThreshold->GetOutput());
		pGeomFilter->Update();

		vtkImageToStructuredPoints* i2sp =
vtkImageToStructuredPoints::New();
		i2sp->SetInput(pMagnitude->GetOutput());
		i2sp->SetVectorInput(pPad->GetOutput());
		i2sp->Update();

		//subpixel them
		vtkSubPixelPositionEdgels* spe =
vtkSubPixelPositionEdgels::New();
		spe->SetInput((vtkPolyData *)pGeomFilter->GetOutput());
		spe->SetGradMaps(i2sp->GetOutput());
		spe->Update();

		vtkStripper* strip = vtkStripper::New();
		strip->SetInput(spe->GetOutput());
		strip->Update();

		vtkPolyDataMapper* dsm = vtkPolyDataMapper::New();
		dsm->SetInput(strip->GetOutput());
		//dsm->SetStartVisibilityOff();
		dsm->Update();

		vtkActor* actor = vtkActor::New();
		actor->SetMapper(dsm);
//[planeActor GetProperty] SetAmbient 1.0
//[planeActor GetProperty] SetDiffuse 0.0

		//render
		vtkRenderer *ren1 = vtkRenderer::New();
		ren1->AddActor(actor);
		vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->OffScreenRenderingOn();
		renWin->AddRenderer(ren1);
		renWin->Render();

		//get contents from window into image
		vtkWindowToImageFilter *w2if =
vtkWindowToImageFilter::New();
		w2if->SetInput(renWin); 
		this->pImage = w2if->GetOutput();  //where pImage is
vtkImageData*

-----Original Message-----
From: Daniel Sidobre [mailto:daniel.sidobre at laas.fr] 
Sent: Friday, October 08, 2004 10:34 AM
To: Bahr, Brian
Cc: vtkusers at vtk.org
Subject: [FILTERED] - [vtkusers] Canny - TCL to C++ conversion -
Bayesian Filter detected spam


Vous avez ecrit (dans votre message du 8 10 2004)
 > I am trying to create a Canny filter in C++.  I can successfully run
the
 > Canny.tcl example, but I am having a hard time converting the Tcl
code
 > into a C++ equivalent.

 Hi,

 So, I suppose you have write some Tcl code to create some Canny
 filter that you run successfully. And you want to translate it in c++.

 As a so general question the response is : it's probably impossible
 as Tcl has many concept that doesn't exist in c++. For example you
 can redefine all functions, you can evaluate expressions in differents
 stack levels, ...

 But, if from the begening of your writing, you have had in mind that
 you want to translate to c++, the job may be pretty easy. For each
 line add some comas and brackets and suppress some dollars.

 Daniel




More information about the vtkusers mailing list