Subject: CGAL users discussion list
List archive
- From: Keith Ealanta <>
- To:
- Subject: Re: [cgal-discuss] More problems filling holes...
- Date: Mon, 12 Feb 2007 01:30:02 +1100
Oops, here are those files...
Keith
// This is the main DLL file.
#include "stdafx.h"
#include "CGAL_Access.h"
namespace CGAL_Access {
void error_handler(const char *type,
const char *expr,
const char *file,
int line,
const char *msg)
{
/* report the error in some way. */
}
AreaData::AreaData()
{
CGAL::set_error_handler(error_handler);
CGAL::set_warning_handler(error_handler);
polygon=NULL;
}
AreaData::~AreaData()
{
if (polygon != NULL)
{
delete polygon;
}
}
Area::Area()
{
x=0.0;
y=0.0;
data = new AreaData();
}
Area::~Area()
{
if (data != NULL)
{
delete data;
}
}
void Area::SetCenter(float x_center,float y_center)
{
x = x_center;
y = y_center;
}
void Area::AddPoint(float x_pos,float y_pos)
{
if (data->polygon == NULL)
{
data->polygon = new Polygon_2();
}
data->polygon->push_back ( Point_2(x_pos,y_pos) );
}
void Area::ClosePolygon()
{
if (data->polygon != NULL)
{
if (data->polygon->size()>2)
{
if (data->polygon->is_clockwise_oriented())
{
data->polygon->reverse_orientation();
}
data->total_area.join(*(data->polygon));
}
ClearPolygon();
}
}
void Area::ClearPolygon()
{
if (data->polygon != NULL)
{
delete data->polygon;
data->polygon = NULL;
}
}
void print_ccb
(CGAL::Polygon_set_2<Kernel>::Arrangement_2::Ccb_halfedge_const_circulator
circ)
{
CGAL::Polygon_set_2<Kernel>::Arrangement_2::Ccb_halfedge_const_circulator
curr = circ;
std::cout << "Is_on_hole = " << circ->is_on_hole() << " : ";
std::cout << "(" << curr->source()->point() << ")";
do {
Arrangement_2::Halfedge_const_handle he =
curr->next();
std::cout // << " [" << curr->curve() << "] "
<< "(" << curr->target()->point() << ")";
} while (++curr != circ);
std::cout << std::endl;
}
void delete_hole (Arrangement_2 &arr,
CGAL::Polygon_set_2<Kernel>::Arrangement_2::Ccb_halfedge_circulator circ)
{
CGAL::Polygon_set_2<Kernel>::Arrangement_2::Ccb_halfedge_circulator curr =
circ;
std::cout << "Is_on_hole = " << circ->is_on_hole() << " : ";
std::cout << "(" << curr->source()->point() << ")";
do {
Arrangement_2::Halfedge_handle he = curr;
std::cout << "(" << curr->target()->point() << ")" <<
std::endl;
curr++;
remove_edge(arr,he);
} while (1==0 /*curr!=circ*/);
std::cout << std::endl;
}
void Area::DebugDump()
{
bool result = false;
Arrangement_2 arr=data->total_area.arrangement();
Arrangement_2::Face_iterator fi;
std::cout << "Arrangement Details --------- " <<
arr.number_of_faces() << " faces." << std::endl;
for (fi=arr.faces_begin();fi!= arr.faces_end();fi++)
{
std::cout << "### Face ###" << std::endl;
if (fi->is_unbounded())
{
std::cout << "Unbounded Face" << std::endl;
}
else
{
std::cout << "Border : " ;
print_ccb(fi->outer_ccb());
std::cout << std::endl;
}
std::cout << "Hole count : " << fi->number_of_holes()
<< std::endl;
std::cout << "---------" << std::endl;
Arrangement_2::Hole_iterator hi;
int cnter = 0;
for( hi = fi->holes_begin();hi!=fi->holes_end();hi++)
{
std::cout << "hole - " << ++cnter <<
std::endl;
print_ccb(*hi);
std::cout << std::endl;
}
std::cout << std::endl;
}
}
bool Area::FillHollows()
{
DebugDump();
bool result = false;
Arrangement_2 arr = data->total_area.arrangement();
Arrangement_2::Face_iterator fi;
std::cout << "New Arrangement --------- " <<
arr.number_of_faces() << " faces." << std::endl;
for (fi=arr.faces_begin();fi!= arr.faces_end();fi++)
{
std::cout << "### Face ###" << std::endl;
if (fi->is_unbounded())
{
continue;
}
std::cout << "Border : " ;
print_ccb(fi->outer_ccb());
std::cout << std::endl;
std::cout << "Hole count : " << fi->number_of_holes()
<< std::endl;
std::cout << "---------" << std::endl;
Arrangement_2::Hole_iterator hi;
int cnter = 0;
while( fi->holes_begin()!=fi->holes_end())
{
hi = fi->holes_begin();
std::cout << "hole - " << ++cnter <<
std::endl;
print_ccb(*hi);
std::cout << std::endl;
delete_hole(arr,*hi);
// remove_edge(arr,fi->holes_begin());
//
fi.current_iterator()->erase_hole(fi->holes_begin());
result = true;
}
std::cout << std::endl;
}
DebugDump();
return result;
}
Area^ Area::Intersection(Area^ Other)
{
Area^ result = gcnew Area();
result->data->total_area=data->total_area;
result->data->total_area.intersection(Other->data->total_area);
return result;
}
Area^ Area::Join(Area^ Other)
{
Area^ result = gcnew Area();
result->data->total_area=data->total_area;
result->data->total_area.join(Other->data->total_area);
return result;
}
Area^ Area::Difference(Area^ Other)
{
Area^ result = gcnew Area();
result->data->total_area=data->total_area;
result->data->total_area.difference(Other->data->total_area);
return result;
}
Area^ Area::Complement(Area^ Other)
{
Area^ result = gcnew Area();
result->data->total_area=data->total_area;
result->data->total_area.complement(Other->data->total_area);
return result;
}
Area^ Area::Symmetric_Difference (Area^ Other)
{
Area^ result = gcnew Area();
result->data->total_area=data->total_area;
result->data->total_area.symmetric_difference(Other->data->total_area);
return result;
}
bool Area::Intersects(Area^ Other)
{
return
(data->total_area.do_intersect(Other->data->total_area));
}
GraphicsPath^ Area::GetOutline()
{
int counter =
data->total_area.number_of_polygons_with_holes();
int sz = 0;
if (counter>0) {
// Print the result.
std::list<Polygon_with_holes_2> res;
std::list<Polygon_with_holes_2>::const_iterator it;
data->total_area.polygons_with_holes
(std::back_inserter (res));
int pos=0;
array<PointF>^ myPoints;
array<Byte>^ myPtTypes;
bool firstpoint = true;
for (it = res.begin(); it != res.end(); ++it) {
Polygon_with_holes_2 pwh = *(it);
sz += pwh.outer_boundary().size();
Array::Resize(myPoints,sz);
Array::Resize(myPtTypes,sz);
firstpoint = true;
VertexIterator vit;
for (vit =
pwh.outer_boundary().vertices_begin(); vit !=
pwh.outer_boundary().vertices_end(); ++vit)
{
myPoints[pos].X = (float)vit->x();
myPoints[pos].Y = (float)vit->y();
if (firstpoint )
{
firstpoint = false;
myPtTypes[pos] =
(Byte)PathPointType::Start;
}
else
{
myPtTypes[pos] =
(Byte)PathPointType::Line;
}
pos++;
}
myPtTypes[pos-1] = (Byte)PathPointType::Line
| (Byte)PathPointType::CloseSubpath;
if (pwh.has_holes())
{
Polygon_with_holes_2::Hole_const_iterator it_inner;
for (it_inner = pwh.holes_begin();
it_inner != pwh.holes_end(); ++it_inner)
{
Polygon_2 pwh_inner =
*(it_inner);
sz += pwh_inner.size();
Array::Resize(myPoints,sz);
Array::Resize(myPtTypes,sz);
bool firstpoint = true;
VertexIterator vit_inner;
for (vit_inner =
pwh_inner.vertices_begin(); vit_inner != pwh_inner.vertices_end();
++vit_inner)
{
myPoints[pos].X =
(float)vit_inner->x();
myPoints[pos].Y =
(float)vit_inner->y();
if (firstpoint)
{
firstpoint =
false;
myPtTypes[pos] = (Byte)PathPointType::Start;
}
else
{
myPtTypes[pos] = (Byte)PathPointType::Line;
}
pos++;
}
myPtTypes[pos-1] =
(Byte)PathPointType::Line | (Byte)PathPointType::CloseSubpath;
}
}
}
GraphicsPath^ outline = gcnew
GraphicsPath(myPoints,myPtTypes);
return outline;
}
else
{
GraphicsPath^ outline = gcnew GraphicsPath();
return outline;
}
}
}
// CGAL_Access.h
#pragma once
#pragma warning( once : 4561 4996)
#include <CGAL/Cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
typedef CGAL::Cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set_2;
typedef CGAL::Polygon_2<Kernel>::Vertex_const_iterator VertexIterator;
typedef CGAL::Polygon_set_2<Kernel>::Arrangement_2 Arrangement_2;
typedef CGAL::Arr_accessor<Arrangement_2> Arr_accessor;
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
#include <CGAL/assertions.h>
namespace CGAL_Access {
public ref class Point
{
public:
float x,y;
};
public class AreaData
{
public:
Polygon_2 *polygon;
Polygon_set_2 total_area;
AreaData();
~AreaData();
};
public ref class Area : public Point
{
private:
AreaData* data;
// TODO: Add your methods for this class here.
public:
Area();
~Area();
bool Intersects(Area^ Other);
Area^ Intersection(Area^ Other);
Area^ Join(Area^ Other);
Area^ Difference(Area^ Other);
Area^ Complement(Area^ Other);
Area^ Symmetric_Difference(Area^ Other);
void SetCenter(float x_center,float y_center);
void AddPoint(float x_pos,float y_pos);
void ClosePolygon(); // Close the current point list as a
polygon.
void ClearPolygon(); // Not needed initially. Use to clear
the polygon under construction so a new one can be created.
bool FillHollows(); // Make the polygons no longer have any
holes. Returns true if any were filled
void DebugDump(); // Print info on the total_area to aid
debugging
GraphicsPath^ Area::GetOutline();
};
}
- More problems filling holes..., Keith Ealanta, 02/06/2007
- Re: [cgal-discuss] More problems filling holes..., Keith Ealanta, 02/06/2007
- Re: [cgal-discuss] More problems filling holes..., Efraim Fogel, 02/06/2007
- Re: [cgal-discuss] More problems filling holes..., Keith Ealanta, 02/11/2007
- Re: [cgal-discuss] More problems filling holes..., Keith Ealanta, 02/11/2007
- Problem with conversions, Olivier Tournaire, 02/11/2007
- Re: [cgal-discuss] Problem with conversions, Sylvain Pion, 02/11/2007
- Problem with conversions, Olivier Tournaire, 02/11/2007
- Re: [cgal-discuss] More problems filling holes..., Efi Fogel, 02/11/2007
- Re: [cgal-discuss] More problems filling holes..., Keith Ealanta, 02/11/2007
- Re: [cgal-discuss] More problems filling holes..., Keith Ealanta, 02/11/2007
Archive powered by MHonArc 2.6.16.