# Generate STL file

**URL:** https://discourse.vtk.org/t/generate-stl-file/4443
**Category:** Support
**Created:** [October 19, 2020, 10:31am UTC](https://discourse.vtk.org/t/generate-stl-file/4443 "2020-10-19T10:31:59Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [October 23, 2020, 9:24am UTC](https://discourse.vtk.org/t/generate-stl-file/4443/9 "2020-10-23T09:24:53Z")

</div>

I am even close to finish line.  
I wrote this:

```
	vtkSmartPointer<vtkTriangleFilter> triangle = vtkSmartPointer<vtkTriangleFilter>::New();
	triangle->SetInputConnection(geometryfilter->GetOutputPort());
	triangle->Update();
	vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
	normals->SetInputConnection(triangle->GetOutputPort());
	normals->Update();

	vtkSmartPointer<vtkSTLWriter> writer = vtkSmartPointer<vtkSTLWriter>::New();
	writer->SetInputConnection(normals->GetOutputPort());
	writer->SetFileName(sSTL);
	writer->SetFileTypeToBinary();
	writer->Write();

```

and from this I got:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/cdab72e89e6e6581d67a9887b8683de0074c4351.png)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/18bbc1f2a810f6ca46615543bfa92b477bb6c5c9.png)

Now, I need just one thing: to filter the outline (contour) of the image, that is all. How can I achieve this ?

In my trials, I have tried to use **vtkMarchingSquares** , I don’t know if is a good idea:

```
	vtkSmartPointer<vtkMarchingSquares> contour = vtkSmartPointer<vtkMarchingSquares>::New();
	contour->SetInputConnection(reader->GetOutputPort());
	contour->GenerateValues(1, 0, 100);
	contour->Update();

```

at _contour-\>Update_ I got a crash:

Program:

```
HEAP CORRUPTION DETECTED: after Normal block (#32114) at 0x000002AAF694F070.
CRT detected that the application wrote to memory after end of heap buffer.

```

I cannot coupling **vtkJPEGReader** to a **vtkMarchingSquares** directly ? But how then ?

What I intend to do is what I found here: [http://vtk.1045678.n5.nabble.com/2D-Surface-Plot-how-to-get-quot-outlines-quot-td1236435.html#a1236436](http://vtk.1045678.n5.nabble.com/2D-Surface-Plot-how-to-get-quot-outlines-quot-td1236435.html#a1236436)

---

_[View the full topic](https://discourse.vtk.org/t/generate-stl-file/4443)._
