tuto_dual3.cpp 5.36 KB
Newer Older
untereiner's avatar
untereiner 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h"

#include "Geometry/vector_gen.h"

#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include <typeinfo>

#include "Algo/Modelisation/subdivision3.h"

using namespace CGoGN ;

/**
 * Struct that contains some informations about the types of the manipulated objects
 * Mainly here to be used by the algorithms that are parameterized by it
 */
struct PFP: public PFP_STANDARD
{
	// definition of the map
	typedef EmbeddedMap3 MAP;
};

Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;

untereiner's avatar
untereiner committed
53 54 55 56 57 58 59 60 61 62
int main(int argc, char **argv)
{
	if(argc != 2)
	{
		CGoGNout << "Usage : " << argv[0] << " filename" << CGoGNendl;
		return 0;
	}

	std::string filename(argv[1]);

63 64 65
	size_t pos = filename.rfind(".");    // position of "." in filename
	std::string extension = filename.substr(pos);

untereiner's avatar
untereiner committed
66
	// declaration of the map
Pierre Kraemer's avatar
Pierre Kraemer committed
67
	MAP myMap;
untereiner's avatar
untereiner committed
68 69

	std::vector<std::string> attrNames ;
70 71 72 73 74

	if (extension == std::string(".map"))
		myMap.loadMapBin(filename);
	else
		Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames);
untereiner's avatar
untereiner committed
75 76

	// get a handler to the 3D vector attribute created by the import
77
	VertexAttribute<VEC3, MAP> position = myMap.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]);
untereiner's avatar
untereiner committed
78

79 80
	// Les faces vont devenir des aretes -> echange de FACE ET EDGE

81
	VolumeAttribute<VEC3, MAP> positionV = myMap.getAttribute<VEC3, VOLUME, MAP>("position") ;
untereiner's avatar
untereiner committed
82
	if(!positionV.isValid())
83
		positionV = myMap.addAttribute<VEC3, VOLUME, MAP>("position") ;
untereiner's avatar
untereiner committed
84

untereiner's avatar
untereiner committed
85
	Algo::Volume::Geometry::computeCentroidVolumes<PFP>(myMap, position, positionV) ;
untereiner's avatar
untereiner committed
86 87 88 89

	Dart dsave = NIL;
	for(Dart d = myMap.begin() ; d != myMap.end() ; myMap.next(d))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
90
		if(myMap.isBoundaryMarked<3>(d))
untereiner's avatar
untereiner committed
91 92 93 94 95 96
		{
			dsave = d;
			break;
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
97
	Dart dcenter = myMap.explodBorderTopo(/*dsave*/);
98

Pierre Kraemer's avatar
Pierre Kraemer committed
99
	DartMarker<MAP> mf(myMap);
100 101
	for(Dart dit = myMap.begin() ; dit != myMap.end() ; myMap.next(dit))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
102
		if(myMap.isBoundaryMarked<3>(dit) && !mf.isMarked(dit))
103 104 105 106 107 108 109 110
		{
			mf.markOrbit<FACE>(dit);
			positionV[dit] = Algo::Surface::Geometry::faceCentroid<PFP>(myMap,dit,position);
		}
	}

	for(Dart dit = myMap.begin() ; dit != myMap.end() ; myMap.next(dit))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
111
		if(myMap.isBoundaryMarked<3>(dit))
112 113 114 115 116 117 118 119
		{
			myMap.fillHole(dit);
		}
	}

	//
	//Compute Dual Test -- begin
	//
120 121 122 123
	DartAttribute<Dart, MAP> old_phi1 = myMap.getAttribute<Dart, DART, MAP>("phi1") ;
	DartAttribute<Dart, MAP> old_phi_1 = myMap.getAttribute<Dart, DART, MAP>("phi_1") ;
	DartAttribute<Dart, MAP> new_phi1 = myMap.addAttribute<Dart, DART, MAP>("new_phi1") ;
	DartAttribute<Dart, MAP> new_phi_1 = myMap.addAttribute<Dart, DART, MAP>("new_phi_1") ;
124

125 126
	DartAttribute<Dart, MAP> old_phi2 = myMap.getAttribute<Dart, DART, MAP>("phi2") ;
	DartAttribute<Dart, MAP> new_phi2 = myMap.addAttribute<Dart, DART, MAP>("new_phi2") ;
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

	for(Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
	{
		Dart dd = myMap.phi2(myMap.phi3(d)) ;
		new_phi1[d] = dd ;
		new_phi_1[dd] = d ;

		Dart ddd = myMap.phi1(myMap.phi3(d));
		new_phi2[d] = ddd;
		new_phi2[ddd] = d;
	}

	myMap.swapAttributes<Dart>(old_phi1, new_phi1) ;
	myMap.swapAttributes<Dart>(old_phi_1, new_phi_1) ;
	myMap.swapAttributes<Dart>(old_phi2, new_phi2) ;

	myMap.removeAttribute(new_phi1) ;
	myMap.removeAttribute(new_phi_1) ;
	myMap.removeAttribute(new_phi2) ;

	myMap.swapEmbeddingContainers(VERTEX, VOLUME) ;

	//
	//ComputeDualTest -- end
	//

	myMap.createHole(dcenter);
untereiner's avatar
untereiner committed
154

155
	VolumeAttribute<VEC3, MAP> del;
156
	del = position;
untereiner's avatar
untereiner committed
157 158
	position = positionV ;

159
	myMap.removeAttribute(del);
untereiner's avatar
untereiner committed
160

161
	myMap.dumpAttributesAndMarkers();
untereiner's avatar
untereiner committed
162 163 164 165 166 167

	myMap.saveMapBin("result.map");
	std::cout << "Exported" << std::endl;

	return 0;
}