# how to get the boundary?

**URL:** https://discourse.vtk.org/t/how-to-get-the-boundary/12864
**Category:** Support
**Created:** [December 7, 2023, 6:07am UTC](https://discourse.vtk.org/t/how-to-get-the-boundary/12864 "2023-12-07T06:07:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Nattu\_Natasha](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nattu_natasha/32/8075_2.png) [@Nattu\_Natasha](https://discourse.vtk.org/u/Nattu_Natasha)
#### Post date: [December 7, 2023, 6:07am UTC](https://discourse.vtk.org/t/how-to-get-the-boundary/12864/1 "2023-12-07T06:07:16Z")

</div>

I have an STL file which is a block support. after slicing the STL file , when I try to print the layer I am only getting inner lines , I am loosing the outer lines {boarder} . posting some pictures for reference. Is there any thing that I am missing in my code? is there any class or function with can I get my boundary lines. please let me know.  
below is the code I wrote

#include\<vtkSmartPointer.h\>  
#include\<vtkPolyData.h\>  
#include\<vtkSTLReader.h\>  
#include\<vtkPlane.h\>  
#include\<vtkPlaneCutter.h\>  
#include\<vtkStripper.h\>  
#include\<vtkCleanPolyData.h\>  
#include\<vtkStaticCleanPolyData.h\>  
#include\<vtkCellArrayIterator.h\>   
#include  
#include  
#include

struct point  
{  
double x, y;  
};

struct line  
{  
point start, end;  
};

int main()  
{

```
//creating stl reader
//C:/Users/durga.pp/Downloads/Box_0m_support.stl
//C:/Users/durga.pp/Downloads/top_support_0m.stl
const char* filename = "C:/Users/durga.pp/Downloads/Box_0m_support.stl";
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(filename);
reader->Update();

//throw an error if file doesn't find
if (reader->GetOutput() == nullptr)
{
	std::cerr << "STL file not found\n";
	return EXIT_FAILURE;
}

//create a polydata
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();

//create a bound
double bound[6];
polydata->GetBounds(bound);

//creating a plane
vtkSmartPointer<vtkPlane> slicing_plane = vtkSmartPointer<vtkPlane>::New();
slicing_plane->SetOrigin(0, 0,bound[4] );
slicing_plane->SetNormal(0, 0, 1);

//creating a plane cutter
vtkSmartPointer<vtkPlaneCutter> plane_cutter = vtkSmartPointer<vtkPlaneCutter>::New();
plane_cutter->SetPlane(slicing_plane);
plane_cutter->SetInputData(polydata);
plane_cutter->Update();

//creating a static cleaner and cleaning the plane cutter
vtkSmartPointer<vtkStaticCleanPolyData> cleaner = vtkSmartPointer<vtkStaticCleanPolyData>::New();
cleaner->SetInputConnection(plane_cutter->GetOutputPort());
cleaner->Update();

//creating a stripper to extract points and lines
vtkSmartPointer<vtkStripper> stripper = vtkSmartPointer<vtkStripper>::New();
stripper->SetInputConnection(plane_cutter->GetOutputPort());
stripper->JoinContiguousSegmentsOn();
stripper->Update();

if (stripper->GetOutput() == nullptr) {
	std::cerr << "Stripped output is null\n";
	return EXIT_FAILURE;
}

vtkPoints* points = stripper->GetOutput()->GetPoints();
vtkCellArray* lines = stripper->GetOutput()->GetLines();

int a = stripper->GetOutput()->GetNumberOfPoints();
int b = stripper->GetOutput()->GetNumberOfLines();

//creating vectros
std::vector<line> hatches;
std::vector<std::vector<point>> Lines_in_Layer;

auto LineIter = vtk::TakeSmartPointer(lines->NewIterator());
for (LineIter->GoToFirstCell(); !LineIter->IsDoneWithTraversal(); LineIter->GoToNextCell())
{
	//HatchEntities::polyline single_region_polyline{};
	vtkIdList* cell = LineIter->GetCurrentCell();
	vtkIdType num = cell->GetNumberOfIds();

	std::vector<point> Current_lines;
	for (vtkIdType i = 0; i < cell->GetNumberOfIds(); ++i)
	{
		double point_[3];
		points->GetPoint(cell->GetId(i), point_);
		point q;
		q.x = point_[0];
		q.y = point_[1];
		Current_lines.push_back(q);
	}

	Lines_in_Layer.push_back(Current_lines);

	line line;
	line.start = Current_lines[0];
	line.end = Current_lines[Current_lines.size() - 1];
	hatches.push_back(line);
}

/*std::ofstream _x, _y;
_x.open("_x.txt");
_y.open("_y.txt");

for (int i = 0; i < Lines_in_Layer.size(); i++)
{
	for (int j = 0; j < Lines_in_Layer[i].size(); j++)
	{
		_x << Lines_in_Layer[i][j].x <<std::endl;
		_y << Lines_in_Layer[i][j].y <<std::endl;
	}
}

_x.close();
_y.close();*/

//Creating the .txt files to store the line points
std::ofstream start_x, start_y, end_x, end_y;
start_x.open("start_x.txt");
start_y.open("start_y.txt");
end_x.open("end_x.txt");
end_y.open("end_y.txt");

for (int i = 0; i < hatches.size(); i++)
{
	start_x << hatches[i].start.x << std::endl;
	start_y << hatches[i].start.y << std::endl;
	end_x << hatches[i].end.x << std::endl;
	end_y << hatches[i].end.y << std::endl;
}

start_x.close();
start_y.close();
end_x.close();
end_y.close();

return 0;

```

}

############################################################  
I am unable to upload the code so I am giving the screenshots of that code please resolve this  
############################################################

 ![actual_problem_statement](https://discourse.vtk.org/uploads/default/original/2X/4/4994333bdf300f2c07ac5c66bc52885c3becae95.png)  
 ![blocksupport_top_view](https://discourse.vtk.org/uploads/default/original/2X/3/302427352725cb46616557068c893c0888f4c6cf.jpeg)  
 ![layer_iam_getting_after_slicing](https://discourse.vtk.org/uploads/default/original/2X/a/ac3a73cb5da805e629e791b3984f9baa4b872a0e.png)  
 ![STL_block_support_file](https://discourse.vtk.org/uploads/default/original/2X/0/0fc1d118fb1fa72448ea8170ed40cb701cc538b4.jpeg)
