importSvg.hpp 16.9 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
...  
untereiner committed
25 26 27 28
#include <iostream>
#include "Geometry/bounding_box.h"
#include "Geometry/plane_3d.h"
#include "Algo/BooleanOperator/mergeVertices.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
#include "Algo/Topo/basic.h"
untereiner's avatar
untereiner committed
30
#include "Container/fakeAttribute.h"
Sylvain Thery's avatar
Sylvain Thery committed
31

untereiner's avatar
...  
untereiner committed
32 33
#include <limits>

Sylvain Thery's avatar
Sylvain Thery committed
34 35
#include "Utils/xml.h" // just for highlighting/completion in editor

untereiner's avatar
...  
untereiner committed
36 37 38 39 40 41
namespace CGoGN
{

namespace Algo
{

42 43 44
namespace Surface
{

untereiner's avatar
...  
untereiner committed
45 46 47
namespace Import
{

Sylvain Thery's avatar
Sylvain Thery committed
48 49 50 51 52 53
//inline bool checkXmlNode(xmlNodePtr node, const std::string& name)
//{
//	return (strcmp((char*)(node->name),(char*)(name.c_str())) == 0);
//}

inline bool checkXmlNode(tinyxml2::XMLElement* node, const std::string& name)
untereiner's avatar
...  
untereiner committed
54
{
Sylvain Thery's avatar
Sylvain Thery committed
55
	return (strcmp(node->Name(),name.c_str()) == 0);
untereiner's avatar
...  
untereiner committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
}

template<typename T>
inline bool valueOf(const std::string &s, T &obj)
{
  std::istringstream is(s);
  return is >> obj;
}

template <typename VEC>
bool posSort(const std::pair<VEC, Dart>& a1, const std::pair<VEC, Dart>& a2)
{
	VEC v1 = a1.first;
	VEC v2 = a2.first;
	return v1[0] < v2[0] || (v1[0] == v2[0] && v1[1] < v2[1]);
}

template <typename VEC3>
void getPolygonFromSVG(std::string allcoords, std::vector<VEC3>& curPoly, bool& closedPoly)
{
	closedPoly=false;
	std::stringstream is(allcoords);
	bool relative=false;
	bool push_point;
	std::string coord;
	int mode = -1;

	while ( std::getline( is, coord, ' ' ) )
	{
		float x,y;
		push_point=false;

		if(coord[0]=='m' || coord[0]=='l' || coord[0]=='t') //start point, line or quadratic bezier curve
		{
			mode = 0;
			relative=true;
		}
		else if(coord[0]=='M' || coord[0] == 'L' || coord[0]=='T') //same in absolute coordinates
		{
			mode = 1;
			relative=false;
		}
		else if(coord[0]=='h' || coord[0] == 'H') //horizontal line
		{
			mode = 2;
			relative=(coord[0]=='h');
		}
		else if(coord[0]=='v' || coord[0] == 'V') //vertical line
		{
			mode = 3;
			relative=(coord[0]=='v');
		}
		else if(coord[0]=='c' || coord[0] == 'C') //bezier curve
		{
			mode = 4;
			relative=(coord[0]=='c');
		}
		else if(coord[0]=='s' || coord[0] == 'S' || coord[0]=='q' || coord[0] == 'Q') //bezier curve 2
		{
			mode = 5;
			relative= ((coord[0]=='s') || (coord[0]=='q'));
		}
		else if(coord[0]=='a' || coord[0] == 'A') //elliptic arc
		{
			mode =6;
			relative= (coord[0]=='a');
		}
123
		else if(coord[0]=='z') //end of path
untereiner's avatar
...  
untereiner committed
124 125
		{
			closedPoly = true;
Jund Thomas's avatar
Jund Thomas committed
126

untereiner's avatar
...  
untereiner committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
		}
		else //coordinates
		{
			switch(mode)
			{
				case 0 : //relative
				break;
				case 1 : //absolute
				break;
				case 2 : //horizontal
				{
					std::stringstream streamCoord(coord);
					std::string xS;
					std::getline(streamCoord, xS, ',' );

					valueOf(xS,x);

					VEC3 previous = (curPoly)[(curPoly).size()-1];
					y = previous[1];

					push_point=true;
				}
				break;
				case 3 : //vertical
				{
					std::stringstream streamCoord(coord);
					std::string yS;
					std::getline(streamCoord, yS, ',' );

					valueOf(yS,y);

untereiner's avatar
untereiner committed
158
					VEC3 previous = (curPoly)[(curPoly).size()-1];
untereiner's avatar
...  
untereiner committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
					x = previous[0];

					push_point=true;
				}
				break;
				case 4 : //bezier
				{
					std::getline( is, coord, ' ' ); //ignore first control point
					std::getline( is, coord, ' ' ); //ignore second control point
				}
				break;
				case 5 : //bezier 2
				{
					std::getline( is, coord, ' ' ); //ignore control point

				}
				break;
				case 6 : //elliptic
					std::getline( is, coord, ' ' ); //ignore rx
					std::getline( is, coord, ' ' ); //ignore ry
					std::getline( is, coord, ' ' ); //ignore x-rotation
					std::getline( is, coord, ' ' ); //ignore large arc flag
					std::getline( is, coord, ' ' ); //ignore sweep flag
				break;
			}

			std::stringstream streamCoord(coord);
			std::string xS,yS;
			std::getline(streamCoord, xS, ',' );
			std::getline(streamCoord, yS, ',' );

			valueOf(xS,x);
			valueOf(yS,y);

			push_point = true;
		}

		//if there is a point to push
		if(push_point)
		{

			VEC3 previous;

			if(curPoly.size()>0)
				previous = (curPoly)[(curPoly).size()-1];

			if(relative)
			{
				x += previous[0];
				y += previous[1];
			}

			if(curPoly.size()==0 || (curPoly.size()>0 && (x!=previous[0] || y!= previous[1])))
				curPoly.push_back(VEC3(x,y,0));
		}
	}
}

217
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
218
void readCoordAndStyle(tinyxml2::XMLElement* cur_path,
219 220 221 222 223 224 225 226 227 228 229
		std::vector<std::vector<VEC3 > >& allPoly,
		std::vector<std::vector<VEC3 > >& allBrokenLines,
		std::vector<float>& allBrokenLinesWidth)
{
	typedef typename PFP::VEC3 VEC3;
	typedef std::vector<VEC3 > POLYGON;

	bool closedPoly;
	POLYGON curPoly;

//	CGoGNout << "--load a path--"<< CGoGNendl;
Sylvain Thery's avatar
Sylvain Thery committed
230 231 232 233
//	xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "d");
//	std::string allcoords((reinterpret_cast<const char*>(prop)));
	std::string allcoords = XMLAttribute(cur_path,"d");

234 235 236 237 238
	getPolygonFromSVG(allcoords,curPoly,closedPoly);

	//check orientation : set in CCW
	if(curPoly.size()>2)
	{
Sylvain Thery's avatar
Sylvain Thery committed
239
		VEC3 v(0)/*, v1, v2*/;
Jund Thomas's avatar
Jund Thomas committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
		typename std::vector<VEC3 >::iterator it0, it1, it2;
		it0 = curPoly.begin();
		it1 = it0+1;
		it2 = it1+1;
		for(unsigned int i = 0 ; i < curPoly.size() ; ++i)
		{
			VEC3 t = (*it1)^(*it0);
			v += t;

			it0=it1;
			it1=it2;
			it2++;
			if(it2 == curPoly.end())
				it2 = curPoly.begin();
		}

		if(v[2]>0)
257 258 259 260 261 262 263 264 265 266 267 268
		{
			std::reverse(curPoly.begin(), curPoly.end());
		}
	}

	//closed polygon ?
	if(closedPoly)
		allPoly.push_back(curPoly);
	else
	{
		//if not : read the linewidth for further dilatation
		allBrokenLines.push_back(curPoly);
Sylvain Thery's avatar
Sylvain Thery committed
269 270 271 272 273

//		xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "style");
//		std::string allstyle((reinterpret_cast<const char*>(prop)));

		std::string allstyle = XMLAttribute(cur_path,"style");
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
		std::stringstream is(allstyle);
		std::string style;
		while ( std::getline( is, style, ';' ) )
		{
			if(style.find("stroke-width:")!=std::string::npos)
			{
				std::stringstream isSize(style);
				std::getline( isSize, style, ':' );
				float sizeOfLine;
				isSize >> sizeOfLine;
				allBrokenLinesWidth.push_back(sizeOfLine);
			}
		}
	}
}

untereiner's avatar
...  
untereiner committed
290
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
291
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& position, CellMarker<typename PFP::MAP,EDGE>& obstacleMark, CellMarker<typename PFP::MAP,FACE>& buildingMark)
untereiner's avatar
...  
untereiner committed
292
{
293 294 295
	//TODO : remove auto-intersecting faces
	//TODO : handling polygons with holes

untereiner's avatar
...  
untereiner committed
296
	typedef typename PFP::VEC3 VEC3;
David Cazier's avatar
David Cazier committed
297
	typedef std::vector<VEC3> POLYGON;
untereiner's avatar
...  
untereiner committed
298

Sylvain Thery's avatar
Sylvain Thery committed
299 300 301 302 303 304 305 306 307 308 309 310

	tinyxml2::XMLDocument doc;
	tinyxml2::XMLError eResult = doc.LoadFile(filename.c_str());

	if (XMLisError(eResult,"unable loading file"+filename))
		return false;

	tinyxml2::XMLElement* map_node = doc.RootElement();


//	xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
//	xmlNodePtr map_node = xmlDocGetRootElement(doc);
untereiner's avatar
...  
untereiner committed
311 312 313 314 315 316 317 318 319 320 321

	if (!checkXmlNode(map_node,"svg"))
	{
		CGoGNerr << "Wrong xml format: Root node != svg"<< CGoGNendl;
		return false;
	}

	std::vector<POLYGON> allPoly;
	std::vector<POLYGON> allBrokenLines;
	std::vector<float> allBrokenLinesWidth;

Sylvain Thery's avatar
Sylvain Thery committed
322
	for (tinyxml2::XMLElement* cur_node = map_node->FirstChildElement(); cur_node; cur_node = cur_node->NextSiblingElement())
untereiner's avatar
...  
untereiner committed
323 324 325
	{
		// for each layer
		if (checkXmlNode(cur_node, "g"))
Sylvain Thery's avatar
Sylvain Thery committed
326
			for (tinyxml2::XMLElement* cur_path = cur_node->FirstChildElement(); cur_path; cur_path = cur_path->NextSiblingElement())
untereiner's avatar
...  
untereiner committed
327 328
			{
				if (checkXmlNode(cur_path, "path"))
329
					readCoordAndStyle<PFP>(cur_path, allPoly, allBrokenLines, allBrokenLinesWidth);
untereiner's avatar
...  
untereiner committed
330
			}
331 332
		else if (checkXmlNode(cur_node, "path"))
				readCoordAndStyle<PFP>(cur_node, allPoly, allBrokenLines, allBrokenLinesWidth);
untereiner's avatar
...  
untereiner committed
333 334
	}

Sylvain Thery's avatar
Sylvain Thery committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348
//	for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next)
//	{
//		// for each layer
//		if (checkXmlNode(cur_node, "g"))
//			for (xmlNode* cur_path = cur_node->children ; cur_path; cur_path = cur_path->next)
//			{
//				if (checkXmlNode(cur_path, "path"))
//					readCoordAndStyle<PFP>(cur_path, allPoly, allBrokenLines, allBrokenLinesWidth);
//			}
//		else if (checkXmlNode(cur_node, "path"))
//				readCoordAndStyle<PFP>(cur_node, allPoly, allBrokenLines, allBrokenLinesWidth);
//	}

//	xmlFreeDoc(doc);
untereiner's avatar
...  
untereiner committed
349

350 351
	std::cout << "importSVG : XML read." << std::endl;

Sylvain Thery's avatar
Sylvain Thery committed
352 353
	CellMarker<typename PFP::MAP,EDGE> brokenMark(map);
	EdgeAttribute<float,typename PFP::MAP> edgeWidth = map.template addAttribute<float, EDGE,typename PFP::MAP>("width");
354
//	EdgeAttribute<NoMathAttribute<Geom::Plane3D<typename PFP::REAL> > > edgePlanes = map.template addAttribute<NoMathAttribute<Geom::Plane3D<typename PFP::REAL> >, EDGE>("planes");
Sylvain Thery's avatar
Sylvain Thery committed
355
	EdgeAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> >, typename PFP::MAP> edgePlanes = map.template addAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> >, EDGE,typename PFP::MAP>("planes");
untereiner's avatar
...  
untereiner committed
356 357
	/////////////////////////////////////////////////////////////////////////////////////////////
	//create broken lines
Sylvain Thery's avatar
Sylvain Thery committed
358
	DartMarker<typename PFP::MAP> brokenL(map);
untereiner's avatar
...  
untereiner committed
359

David Cazier's avatar
David Cazier committed
360
	typename std::vector<POLYGON >::iterator it;
untereiner's avatar
...  
untereiner committed
361
	std::vector<float >::iterator itW = allBrokenLinesWidth.begin();
David Cazier's avatar
David Cazier committed
362
	for(it = allBrokenLines.begin() ; it != allBrokenLines.end() ; ++it, ++itW)
untereiner's avatar
...  
untereiner committed
363 364 365 366 367 368 369 370
	{
		if(it->size()<2)
		{
			it = allBrokenLines.erase(it);
			itW = allBrokenLinesWidth.erase(itW);
		}
		else
		{
David Cazier's avatar
David Cazier committed
371
			Dart d = map.newPolyLine(it->size()-1);
untereiner's avatar
...  
untereiner committed
372

David Cazier's avatar
David Cazier committed
373
			for(typename POLYGON::iterator emb = it->begin(); emb != it->end() ; emb++)
untereiner's avatar
...  
untereiner committed
374
			{
David Cazier's avatar
David Cazier committed
375 376
				brokenL.mark(d);
				brokenL.mark(map.phi2(d));
377

David Cazier's avatar
David Cazier committed
378
				edgeWidth[d] = *itW;
Jund Thomas's avatar
Jund Thomas committed
379 380
				if (*itW == 0)
					std::cout << "importSVG : null path width" << std::endl ;
David Cazier's avatar
David Cazier committed
381 382
				position[d] = *emb;
				d = map.phi1(d);
untereiner's avatar
...  
untereiner committed
383
			}
384 385
		}
	}
David Cazier's avatar
David Cazier committed
386
	std::cout << "importSVG : broken lines created : " << std::endl;
untereiner's avatar
...  
untereiner committed
387 388

	/////////////////////////////////////////////////////////////////////////////////////////////
David Cazier's avatar
David Cazier committed
389
	// Merge near vertices
Sylvain Thery's avatar
Sylvain Thery committed
390
	BooleanOperator::mergeVertices<PFP>(map,position,1);
391
	std::cout << "importSVG : Merging of vertices." << std::endl;
392

Jund Thomas's avatar
Jund Thomas committed
393
	/////////////////////////////////////////////////////////////////////////////////////////////
394

Jund Thomas's avatar
Jund Thomas committed
395 396
	std::cout << "buildings " << allPoly.size() << std::endl;
	unsigned int c = 0;
untereiner's avatar
...  
untereiner committed
397

Jund Thomas's avatar
Jund Thomas committed
398 399 400
	//create polygons
	for(it = allPoly.begin() ; it != allPoly.end() ; ++it)
	{
David Cazier's avatar
David Cazier committed
401
		if(it->size()<3)
Jund Thomas's avatar
Jund Thomas committed
402 403 404 405 406 407
		{
			it = allPoly.erase(it);
		}
		else
		{
			Dart d = map.newFace(it->size());
Jund Thomas's avatar
Jund Thomas committed
408
			c++;
David Cazier's avatar
David Cazier committed
409 410
			buildingMark.mark(d);
			buildingMark.mark(map.phi2(d));
411

untereiner's avatar
...  
untereiner committed
412 413
			for(typename POLYGON::iterator emb = it->begin(); emb != it->end() ; emb++)
			{
David Cazier's avatar
David Cazier committed
414
				position[d] = *emb;
David Cazier's avatar
David Cazier committed
415
				obstacleMark.mark(d);
David Cazier's avatar
David Cazier committed
416
				d = map.phi1(d);
untereiner's avatar
...  
untereiner committed
417
			}
418
		}
Jund Thomas's avatar
Jund Thomas committed
419
	}
untereiner's avatar
...  
untereiner committed
420

David Cazier's avatar
David Cazier committed
421 422 423 424
	Geom::BoundingBox<typename PFP::VEC3> bb ;
	bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
	float tailleX = bb.size(0) ;
	float tailleY = bb.size(1) ;
425
	float tailleM = std::max<float>(tailleX, tailleY) / 30 ;
David Cazier's avatar
David Cazier committed
426 427
	std::cout << "bounding box = " << tailleX << " X " << tailleY << std::endl;

Jund Thomas's avatar
Jund Thomas committed
428 429 430 431
	for(Dart d = map.begin();d != map.end(); map.next(d))
	{
		if(position[d][0] == position[map.phi1(d)][0] && position[d][1] == position[map.phi1(d)][1])
			std::cout << "prob d " << d << std::endl;
432 433
	}

Jund Thomas's avatar
Jund Thomas committed
434
	std::cout << "importSVG : Polygons generated." << std::endl;
435 436

	/////////////////////////////////////////////////////////////////////////////////////////////
437
	unsigned int count = 0 ;
untereiner's avatar
...  
untereiner committed
438 439

	//cut the edges to have a more regular sampling
David Cazier's avatar
David Cazier committed
440 441
	TraversorE<typename PFP::MAP> edges(map) ;
	for (Dart d = edges.begin() ; d != edges.end() ; d = edges.next())
442
	{
David Cazier's avatar
David Cazier committed
443
		if (!buildingMark.isMarked(d))
444 445 446 447
		{
			VEC3 p1 = position[d] ;
			VEC3 p2 = position[map.phi1(d)] ;
			VEC3 v  = p2 - p1 ;
David Cazier's avatar
David Cazier committed
448
			float length = v.norm() ;
449

David Cazier's avatar
David Cazier committed
450
			if (length > tailleM)
451
			{
David Cazier's avatar
David Cazier committed
452
				unsigned int nbSeg = (unsigned int)(length / tailleM) ;
453
				v /= nbSeg ;
David Cazier's avatar
David Cazier committed
454
				count += nbSeg ;
455 456 457

				for (unsigned int i = 0 ; i < nbSeg - 1 ; ++i)
					map.cutEdge(d) ;
untereiner's avatar
...  
untereiner committed
458

459 460 461
				brokenL.mark(d);
				brokenL.mark(map.phi2(d));
				Dart dd = map.phi1(d) ;
untereiner's avatar
...  
untereiner committed
462

463 464 465 466 467 468 469 470 471 472
				for (unsigned int i = 1 ; i < nbSeg ; ++i)
				{
					brokenL.mark(dd);
					brokenL.mark(map.phi2(dd));
					position[dd] = p1 + v * i ;
					dd = map.phi1(dd) ;
				}
			}
		}
	}
David Cazier's avatar
David Cazier committed
473
	std::cout << "importSVG : Subdivision of long edges : " << count << " morceaux."<< std::endl;
untereiner's avatar
...  
untereiner committed
474 475

	/////////////////////////////////////////////////////////////////////////////////////////////
David Cazier's avatar
David Cazier committed
476
	//simplify the edges to have a more regular sampling
David Cazier's avatar
David Cazier committed
477
	count = 0 ;
David Cazier's avatar
David Cazier committed
478 479
	for (Dart d = map.begin() ; d != map.end() ; map.next(d))
	{
David Cazier's avatar
David Cazier committed
480
		if(!buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
481 482
		{
			bool canSimplify = true ;
483
			while ( canSimplify && (Geometry::edgeLength<PFP>(map,d,position) < edgeWidth[d]) )
David Cazier's avatar
David Cazier committed
484
			{
485 486
				if (map.vertexDegree(map.phi1(d)) == 2)
				{
David Cazier's avatar
David Cazier committed
487
					map.uncutEdge(d) ;
David Cazier's avatar
David Cazier committed
488
					count++;
David Cazier's avatar
David Cazier committed
489
				}
490 491
				else
					canSimplify = false ;
David Cazier's avatar
David Cazier committed
492 493 494
			}
		}
	}
David Cazier's avatar
David Cazier committed
495
	std::cout << "importSVG : Downsampling of vertices : " << count << " sommets supprimés." << std::endl;
untereiner's avatar
...  
untereiner committed
496 497 498

	/////////////////////////////////////////////////////////////////////////////////////////////
	//process broken lines
Sylvain Thery's avatar
Sylvain Thery committed
499
	CellMarker<typename PFP::MAP,EDGE> eMTreated(map) ;
500
	for (Dart d = map.begin() ; d != map.end() ; map.next(d))
untereiner's avatar
...  
untereiner committed
501
	{
502
		if (brokenL.isMarked(d) && !eMTreated.isMarked(d))
untereiner's avatar
...  
untereiner committed
503
		{
504 505
			eMTreated.mark(d) ;
			//insert a quadrangular face in the broken line
untereiner's avatar
...  
untereiner committed
506
			// -> we convert broken lines to faces to represent their width
507
			// -> the intersection are then closed
untereiner's avatar
...  
untereiner committed
508

509 510
			Dart d1 = d ;
			Dart d2 = map.phi2(d1) ;
untereiner's avatar
...  
untereiner committed
511

512 513
			map.unsewFaces(d1) ;
			Dart dN = map.newFace(4) ;
untereiner's avatar
...  
untereiner committed
514

515 516 517 518 519 520 521
			VEC3 p1 = position[d1] ;
			VEC3 p2 = position[d2] ;
			VEC3 v = p2 - p1 ;
			VEC3 ortho = v ^ VEC3(0, 0, 1);
			float width = edgeWidth[d1] / 2.0f ;
			ortho.normalize() ;
			v.normalize() ;
untereiner's avatar
...  
untereiner committed
522 523 524

			//if the valence of one of the vertex is equal to one
			//cut the edge to insert the quadrangular face
Jund Thomas's avatar
Jund Thomas committed
525
			if(map.vertexDegree(d1)==2)
untereiner's avatar
...  
untereiner committed
526
			{
527 528 529 530
				map.cutEdge(d2) ;
				brokenL.mark(map.phi1(d2)) ;
				eMTreated.mark(map.phi1(d2)) ;
				map.sewFaces(map.phi_1(d1), map.phi1(dN)) ;
David Cazier's avatar
David Cazier committed
531
				obstacleMark.mark(map.phi_1(d1)) ;
532 533
				position[map.phi_1(d1)] = p1 ;
				edgePlanes[map.phi_1(d1)] = Geom::Plane3D<typename PFP::REAL>(v, p1) ;
untereiner's avatar
...  
untereiner committed
534 535
			}

Jund Thomas's avatar
Jund Thomas committed
536
			if(map.vertexDegree(d2)==2)
537
			{
538 539 540 541
				map.cutEdge(d1) ;
				brokenL.mark(map.phi1(d1)) ;
				eMTreated.mark(map.phi1(d1)) ;
				map.sewFaces(map.phi_1(d2), map.phi_1(dN)) ;
David Cazier's avatar
David Cazier committed
542
				obstacleMark.mark(map.phi_1(d2)) ;
543 544
				position[map.phi_1(d2)] = p2 ;
				edgePlanes[map.phi_1(d2)] = Geom::Plane3D<typename PFP::REAL>(-1.0f * v, p2) ;
545
			}
untereiner's avatar
...  
untereiner committed
546

547
			map.sewFaces(d1, dN) ;
David Cazier's avatar
David Cazier committed
548
			obstacleMark.mark(d1) ;
549
			edgePlanes[d1] = Geom::Plane3D<typename PFP::REAL>(ortho, p1 - (width * ortho)) ;
untereiner's avatar
...  
untereiner committed
550

David Cazier's avatar
David Cazier committed
551 552
			map.sewFaces(d2, map.phi1(map.phi1(dN))) ;
			obstacleMark.mark(d2) ;
553
			edgePlanes[d2] = Geom::Plane3D<typename PFP::REAL>(-1.0f * ortho, p2 + (width * ortho)) ;
untereiner's avatar
...  
untereiner committed
554 555 556
		}
	}

Jund Thomas's avatar
Jund Thomas committed
557
	if(allBrokenLines.size()>0)
558
	{
Jund Thomas's avatar
Jund Thomas committed
559
		for (Dart d = map.begin() ; d != map.end() ; map.next(d))
560
		{
Sylvain Thery's avatar
Sylvain Thery committed
561
			if(map.template isBoundaryMarked<2>(d))
Jund Thomas's avatar
Jund Thomas committed
562 563
			{
				map.fillHole(d);
untereiner's avatar
...  
untereiner committed
564
			}
565

Jund Thomas's avatar
Jund Thomas committed
566
			if(map.faceDegree(d)==2)
567
			{
Jund Thomas's avatar
Jund Thomas committed
568
				map.mergeFaces(d);
569
			}
570
		}
untereiner's avatar
...  
untereiner committed
571

Jund Thomas's avatar
Jund Thomas committed
572 573
		//embed the path
		for (Dart d = map.begin() ; d != map.end() ; map.next(d))
untereiner's avatar
...  
untereiner committed
574
		{
Jund Thomas's avatar
Jund Thomas committed
575 576 577
			if (brokenL.isMarked(d))
			{
				VEC3 pos;
Jund Thomas's avatar
Jund Thomas committed
578

Jund Thomas's avatar
Jund Thomas committed
579 580
				Geom::Plane3D<typename PFP::REAL> pl;
				pos = position[d] ;
untereiner's avatar
...  
untereiner committed
581

Jund Thomas's avatar
Jund Thomas committed
582 583 584
				pl = edgePlanes[d] ;
				pl.project(pos) ;
				position[d] = pos ;
Jund Thomas's avatar
Jund Thomas committed
585

Jund Thomas's avatar
Jund Thomas committed
586 587 588 589
				pos = position[map.phi1(d)] ;
				pl.project(pos) ;
				position[map.phi1(d)] = pos ;
			}
untereiner's avatar
...  
untereiner committed
590 591
		}

Sylvain Thery's avatar
Sylvain Thery committed
592
		Algo::Topo::initAllOrbitsEmbedding<FACE>(map,true);
untereiner's avatar
...  
untereiner committed
593

594
		for (Dart d = map.begin() ; d != map.end() ; map.next(d))
untereiner's avatar
...  
untereiner committed
595
		{
Sylvain Thery's avatar
Sylvain Thery committed
596
			if (!map.template isBoundaryMarked<2>(d) && brokenL.isMarked(d))
597
			{
Sylvain Thery's avatar
Sylvain Thery committed
598 599
				// ??? map.deleteFace(d,false);
				map.deleteCycle(d); // ???
600 601
			}
		}
untereiner's avatar
...  
untereiner committed
602

Jund Thomas's avatar
Jund Thomas committed
603
		map.closeMap();
604

605 606
		for (Dart d = map.begin() ; d != map.end() ; map.next(d))
		{
Sylvain Thery's avatar
Sylvain Thery committed
607
			if (map.template isBoundaryMarked<2>(d))
608
				buildingMark.mark(d);
untereiner's avatar
...  
untereiner committed
609 610
		}

Jund Thomas's avatar
Jund Thomas committed
611
	}
untereiner's avatar
...  
untereiner committed
612 613 614 615

	return true ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
616
} // namespace Import
untereiner's avatar
...  
untereiner committed
617

618 619
}

Pierre Kraemer's avatar
Pierre Kraemer committed
620
} // namespace Algo
untereiner's avatar
...  
untereiner committed
621

Pierre Kraemer's avatar
Pierre Kraemer committed
622
} // namespace CGoGN