importMRDAT.h 5.53 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 25 26 27 28 29 30 31 32 33 34 35 36 37
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#ifndef __IMPORT_MR_DAT__
#define __IMPORT_MR_DAT__

namespace CGoGN
{

namespace Algo
{

namespace Import
{

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
38
bool importMRDAT(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
39

Pierre Kraemer's avatar
Pierre Kraemer committed
40
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42 43 44 45 46 47 48 49
class QuadTreeNode
{
public:
	QuadTreeNode()
	{
		for(unsigned int i = 0; i < 3; ++i)
			indices[i] = -1 ;
		for(unsigned int i = 0; i < 4; ++i)
			children[i] = NULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
50
		parent = NULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
51 52 53 54 55 56 57 58 59 60 61 62 63
	}

	~QuadTreeNode()
	{
		for(unsigned int i = 0; i < 4; ++i)
			if(children[i] != NULL)
				delete children[i] ;
	}

	void subdivide()
	{
		assert(children[0] == NULL) ;
		for(unsigned int i = 0; i < 4; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
64
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
65
			children[i] = new QuadTreeNode() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
			children[i]->parent = this ;
		}
	}

	bool isSubdivided()
	{
		return children[0] != NULL ;
	}

	void embed(typename PFP::MAP& map, Dart d, std::vector<unsigned int>& vID, CellMarker& cm, bool CCW)
	{
		if(isSubdivided())
		{
			Dart d0 = map.phi1(d) ;
			Dart d1, d2 ;
			if(CCW)
			{
				d1 = map.phi_1(d) ;
				d2 = d ;
			}
			else
			{
				d1 = d ;
				d2 = map.phi_1(d) ;
			}
			map.incCurrentLevel() ;
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 123 124 125

			unsigned int emb0 = vID[children[0]->indices[0]] ;
			unsigned int e0 = map.getEmbedding(VERTEX, map.phi2(d0)) ;
			if(!cm.isMarked(map.phi2(d0)))
			{
				assert(e0 == EMBNULL) ;
				map.embedOrbit(VERTEX, map.phi2(d0), emb0) ;
				cm.mark(map.phi2(d0)) ;
			}
			else
				assert(e0 == emb0) ;

			unsigned int emb1 = vID[children[0]->indices[1]] ;
			unsigned int e1 = map.getEmbedding(VERTEX, map.phi2(d1)) ;
			if(!cm.isMarked(map.phi2(d1)))
			{
				assert(e1 == EMBNULL) ;
				map.embedOrbit(VERTEX, map.phi2(d1), emb1) ;
				cm.mark(map.phi2(d1)) ;
			}
			else
				assert(e1 == emb1) ;

			unsigned int emb2 = vID[children[0]->indices[2]] ;
			unsigned int e2 = map.getEmbedding(VERTEX, map.phi2(d2)) ;
			if(!cm.isMarked(map.phi2(d2)))
			{
				assert(e2 == EMBNULL) ;
				map.embedOrbit(VERTEX, map.phi2(d2), emb2) ;
				cm.mark(map.phi2(d2)) ;
			}
			else
				assert(e2 == emb2) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
			map.decCurrentLevel() ;

			Dart t0 = map.phi_1(d) ;
			map.incCurrentLevel() ;
			t0 = map.phi2(map.phi1(t0)) ;
			children[0]->embed(map, t0, vID, cm, CCW) ;
			map.decCurrentLevel() ;

			Dart t1 = d ;
			map.incCurrentLevel() ;
			children[1]->embed(map, t1, vID, cm, !CCW) ;
			map.decCurrentLevel() ;

			Dart t2 = map.phi1(d) ;
			map.incCurrentLevel() ;
			t2 = map.phi1(t2) ;
			children[2]->embed(map, t2, vID, cm, !CCW) ;
			map.decCurrentLevel() ;

			Dart t3 = map.phi_1(d) ;
			map.incCurrentLevel() ;
			t3 = map.phi_1(t3) ;
			children[3]->embed(map, t3, vID, cm, !CCW) ;
			map.decCurrentLevel() ;
		}
151 152 153 154 155
		else
		{
			if(map.getCurrentLevel() < map.getMaxLevel())
				std::cout << "adaptive !!!!!!!" << std::endl ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
156 157 158 159 160 161 162 163 164 165
	}

	void print()
	{
		std::cout << indices[0] << " " << indices[1] << " " << indices[2] << std::endl ;
		if(isSubdivided())
		{
			for(unsigned int i = 0; i < 4; ++i)
				children[i]->print() ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
166 167 168 169
	}

	unsigned int indices[3] ;
	QuadTreeNode* children[4] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
170
	QuadTreeNode* parent ;
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
173
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175 176
class QuadTree
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
177 178
	std::vector<QuadTreeNode<PFP>*> roots ;
	std::vector<Dart> darts ;
Pierre Kraemer's avatar
Pierre Kraemer committed
179 180 181 182 183 184

	~QuadTree()
	{
		for(unsigned int i = 0; i < roots.size(); ++i)
			delete roots[i] ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

	void embed(typename PFP::MAP& map, std::vector<unsigned int>& vID)
	{
		CellMarker cm(map, VERTEX) ;
		for(unsigned int i = 0; i < roots.size(); ++i)
			roots[i]->embed(map, darts[i], vID, cm, true) ;
	}

	void print()
	{
		std::cout << "printing quadtree (" << roots.size() << " roots)" << std::endl ;
		for(unsigned int i = 0; i < roots.size(); ++i)
		{
			std::cout << "root " << i << std::endl ;
			roots[i]->print() ;
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
202 203 204 205 206 207 208 209 210 211 212
} ;

} // namespace Import

} // namespace Algo

} // namespace CGoGN

#include "Algo/Import/importMRDAT.hpp"

#endif