test_mapd1.cpp 5.49 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

#include "Topology/map/map2.h"

using namespace CGoGN;

struct PFP {
	typedef DartObj<DP::MAPD1_V0> DART;
	typedef tMap1<DART> MAP;
};

typedef PFP::MAP::Dart Dart;

int main(int, char**) {
	PFP::MAP myMap;

	Dart d1;
	Dart e1;
	Dart f1;

	// One first edge
	d1 = myMap.newEdge();
	PFP::MAP::OrientedFaceIterator face;
48 49 50
	CGoGNout << "First edge : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
51 52 53

	// Cut first edge gives two edges
	f1 = myMap.cutEdge(d1);
54 55 56
	CGoGNout << "Second edge : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
57 58 59

	// New face with 10 edges
	d1 = myMap.newFace(10);
60 61 62
	CGoGNout << "First face : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 66 67

	// Delete two edges
	myMap.deleteEdgeAfter(d1);
	e1 = myMap.phi1(d1);
	myMap.deleteEdge(e1);
68 69 70
	CGoGNout << "Face with 2 less edges : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73 74 75 76

	// Delete face
	myMap.deleteOrientedFace(d1);
	
	// New face with 10 edges
	d1 = myMap.newFace(10);
77 78 79
	CGoGNout << "Second face : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
80 81 82

	FunctorCount fcount1;
	myMap.foreach_dart_of_face(d1,fcount1);
83
	CGoGNout << "nbEdges = " << fcount1.getNb() << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87 88 89
	
	// Search for the middle of the face and split face
	e1 = d1;
	for (unsigned i=0; i<fcount1.getNb()/2; ++i) e1 = myMap.phi1(e1);
	myMap.splitFace(d1,e1);

90 91
	CGoGNout << "nbEdges d1 = " << myMap.faceDegree(d1) << CGoGNendl;
	CGoGNout << "nbEdges e1 = " << myMap.faceDegree(e1) << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
92

93 94 95
	CGoGNout << "First splitted face : ";
	for (face.begin(d1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
96

97 98 99
	CGoGNout << "Second splitted face : ";
	for (face.begin(e1); !face.end(); ++face) CGoGNout << **face << " ";
	CGoGNout << "(" << face.length() << " traversed darts)" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102

	// Merge splitted faces
	myMap.mergeFaces(d1,e1);
103
	CGoGNout << "nbEdges d1+e1 = " << myMap.faceDegree(d1) << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
104 105 106

	// Reverse linking in the face
	myMap.reverseFace(d1);
107
	if (myMap.sameFace(d1,e1)) CGoGNout << "ok" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
	
	// Test of markers
	Marker m1 = myMap.getNewMarker();
	myMap.markFace(d1,m1);
	myMap.saveMap("test.map",true);
	myMap.saveMapBin("test.bmap");
	myMap.unmarkFace(d1,m1);

	// Free memory
	myMap.deleteOrientedFace(d1);
	myMap.deleteOrientedFace(f1);
	
	// Release Markers
	myMap.releaseMarker(m1);
	
	// Load the saved map
	myMap.loadMap("test.map",true);
125 126
	CGoGNout << "MarkerSet = " << myMap.getMarkerVal() << CGoGNendl;
	CGoGNout << "Boundary Marker = " << myMap.m_BoundaryMarkerVal.getMarkerVal() << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
127
	for (Dart d = myMap.begin(); d != myMap.end(); ++d) {
128
		CGoGNout << "[" << d->getLabel() << "] " << *d << " (" << d->getMarkerVal() << ")" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130 131 132
	}

	// Load a second map (append the load darts)
	myMap.loadMapBin("test.bmap");
133 134
	CGoGNout << "MarkerSet = " << myMap.getMarkerVal() << CGoGNendl;
	CGoGNout << "Boundary Marker = " << myMap.m_BoundaryMarkerVal.getMarkerVal() << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
135
	for (Dart d = myMap.begin(); d != myMap.end(); ++d) {
136
		CGoGNout << "[" << d->getLabel() << "] " << *d << " (" << d->getMarkerVal() << ")" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140 141 142 143 144 145 146
	}

	myMap.unmarkAll(m1);
	myMap.releaseMarker(m1);
	while (myMap.begin() != myMap.end()) {
		myMap.deleteOrientedFace(myMap.begin());
	};
	
	return 0;
}