Commit b2ff35a7 authored by Sylvain Thery's avatar Sylvain Thery

replace MapBrowers by ContainerBrowsers

parent aac0ab43
......@@ -24,7 +24,6 @@
#include "tuto1.h"
#include "Algo/Geometry/boundingbox.h"
#include "Topology/generic/mapBrowser.h"
using namespace CGoGN ;
......
......@@ -290,11 +290,6 @@ void MyQT::createMap(int /*n*/)
m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f);
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3/*, nb*/);
// SelectorDartBoundary<PFP::MAP> sdb(myMap);
// MapBrowserSelector mbs(myMap,sdb);
// myMap.setBrowser(&mbs);
// m_render_topo_boundary->updateData<PFP>(myMap,position,m_ex1,m_ex2);
// myMap.setBrowser(NULL);
m_render_topo_boundary->updateDataBoundary<PFP>(myMap,position,m_ex1,m_ex2,m_shift);
}
......
......@@ -26,7 +26,6 @@
#define __COLOR_APPROXIMATOR_H__
#include "Algo/Decimation/approximator.h"
#include "Topology/generic/mapBrowser.h"
namespace CGoGN
{
......
......@@ -26,7 +26,7 @@
#define __ALGO_GEOMETRY_NORMALIZATION_H__
#include "Geometry/vector_gen.h"
#include "Topology/generic/mapBrowser.h"
#include "Container/containerBrowser.h"
namespace CGoGN
{
......@@ -41,27 +41,50 @@ namespace Geometry
template <typename PFP, unsigned int ORBIT>
typename PFP::REAL normalizeLength(typename PFP::MAP & the_map, AttributeHandler<typename PFP::VEC3,ORBIT> & m_attr, const typename PFP::REAL scale = 1.0, )
{
// typename PFP::REAL sum = 0 ;
// int count = 0 ;
// MapBrowserLinked<typename PFP::MAP> mb(the_map) ;
// the_map.foreach_orbit(m_attr.getOrbit(), mb) ;
// for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
// {
// typename PFP::VEC3 length = m_attr[d] ;
// length -= m_attr[the_map.phi2(d)] ;
// sum += length.norm() ;
// ++count ;
// }
// sum /= typename PFP::REAL(count) ;
// typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
// for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
// {
// m_attr[d] /= div ;
// }
// return div ;
typename PFP::REAL sum = 0 ;
int count = 0 ;
MapBrowserLinked<typename PFP::MAP> mb(the_map) ;
the_map.foreach_orbit(m_attr.getOrbit(), mb) ;
for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
TraversorCell<PFP::MAP,ORBIT> trav(the_map);
for (Dart d = trav.begin(); d != trav.end(); d=trav.next())
{
typename PFP::VEC3 length = m_attr[d] ;
length -= m_attr[the_map.phi2(d)] ;
sum += length.norm() ;
++count ;
sum += length.norm() ;
++count ;
}
sum /= typename PFP::REAL(count) ;
sum /= typename PFP::REAL(count) ;
typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
typename PFP::REAL div = sum / scale ; // mutiply res by scale factor
for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
for (Dart d = trav.begin(); d != trav.end(); d=trav.next())
{
m_attr[d] /= div ;
m_attr[d] /= div ;
}
return div ;
......
......@@ -24,7 +24,8 @@
#ifndef IMPORTOBJTEX_H
#define IMPORTOBJTEX_H
#include "Topology/generic/mapBrowser.h"
//#include "Topology/generic/mapBrowser.h"
#include "Container/containerBrowser.h"
#include "Topology/generic/cellmarker.h"
namespace CGoGN
......@@ -180,7 +181,7 @@ public:
* @param browsers vector of MapBrowers representing the groups
* @return ok or not
*/
bool generateBrowsers(std::vector<MapBrowser*>& browsers);
bool generateBrowsers(std::vector<ContainerBrowser*>& browsers);
/**
* @brief getMaterialNames
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/autoAttributeHandler.h"
#include "Container/fakeAttribute.h"
#include <fstream>
......@@ -214,30 +215,51 @@ void OBJModel<PFP>::readMaterials(const std::string& filename, std::vector<Mater
template <typename PFP>
bool OBJModel<PFP>::generateBrowsers(std::vector<MapBrowser*>& browsers)
bool OBJModel<PFP>::generateBrowsers(std::vector<ContainerBrowser*>& browsers)
{
browsers.clear();
// browsers.clear();
// if (m_groupNames.empty())
// return false;
// MapBrowserLinked* MBLptr = new MapBrowserLinked(m_map);
// DartAttribute<Dart>& links = MBLptr->getLinkAttr();
// browsers.push_back(MBLptr);
// for (unsigned int i = 1; i<m_groupNames.size(); ++i)
// {
// MapBrowser* MBptr = new MapBrowserLinked(m_map,links);
// browsers.push_back(MBptr);
// m_groupMaterialID[i]= m_materialNames[m_groupMaterialNames[i]];
// }
// for (Dart d=m_map.begin(); d!=m_map.end(); m_map.next(d))
// {
// unsigned int g = m_groups[d] -1 ; // groups are name from 1
// MapBrowserLinked* mb = static_cast<MapBrowserLinked*>(browsers[g]);
// mb->pushBack(d);
// }
// return true;
browsers.clear();
if (m_groupNames.empty())
return false;
MapBrowserLinked* MBLptr = new MapBrowserLinked(m_map);
DartAttribute<Dart>& links = MBLptr->getLinkAttr();
ContainerBrowserLinked* MBLptr = new ContainerBrowserLinked(m_map,DART);
browsers.push_back(MBLptr);
for (unsigned int i = 1; i<m_groupNames.size(); ++i)
{
MapBrowser* MBptr = new MapBrowserLinked(m_map,links);
ContainerBrowser* MBptr = new ContainerBrowserLinked(*MBLptr);
browsers.push_back(MBptr);
// std::string& matName = m_materialNames[i];
m_groupMaterialID[i]= m_materialNames[m_groupMaterialNames[i]];
}
for (Dart d=m_map.begin(); d!=m_map.end(); m_map.next(d))
{
unsigned int g = m_groups[d] -1 ; // groups are name from 1
MapBrowserLinked* mb = static_cast<MapBrowserLinked*>(browsers[g]);
mb->pushBack(d);
ContainerBrowserLinked* mb = static_cast<ContainerBrowserLinked*>(browsers[g]);
mb->pushBack(d.index);
}
return true;
}
......
......@@ -35,7 +35,7 @@
#include "Algo/Geometry/centroid.h"
#include "Algo/Geometry/normal.h"
#include "Topology/generic/mapBrowser.h"
#include "Container/containerBrowser.h"
namespace CGoGN
{
......@@ -56,12 +56,18 @@ void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribut
m_normalShift = ns;
// SelectorDartBoundary<typename PFP::MAP> sdb(map);
// MapBrowserSelector mbs(map,sdb);
MapBrowserSelector mbs(map,SelectorDartBoundary<typename PFP::MAP>(map));
map.setBrowser(&mbs);
// MapBrowserSelector mbs(map,SelectorDartBoundary<typename PFP::MAP>(map));
// map.setBrowser(&mbs);
SelectorDartBoundary<typename PFP::MAP> sdb(map);
DartContainerBrowserSelector browser(map,sdb);
browser.enable();
updateData<PFP>(map,positions, ke, kf,true);
map.setBrowser(NULL);
browser.disable();
// map.setBrowser(NULL);
m_normalShift = 0.0f;
}
......
......@@ -53,13 +53,13 @@ namespace CGoGN
* - a MapBrowserSelector
* - a MapBrowserLinked (Attr or Auto)
*/
class MapBrowser
{
public:
virtual Dart begin() const = 0;
virtual Dart end() const = 0;
virtual void next(Dart& d) const = 0;
};
//class MapBrowser
//{
//public:
// virtual Dart begin() const = 0;
// virtual Dart end() const = 0;
// virtual void next(Dart& d) const = 0;
//};
class AttributeHandlerGen ;
class DartMarkerGen ;
......@@ -83,7 +83,7 @@ protected:
/**
* @brief current MapBrowser used to traverse the map
*/
MapBrowser* m_currentBrowser;
// MapBrowser* m_currentBrowser;
/**
* Attributes Containers
......@@ -195,11 +195,11 @@ public:
template <unsigned int ORBIT>
MarkSet& getMarkerSet(unsigned int thread = 0) { return m_marksets[ORBIT][thread]; }
/**
* @brief set the current MapBrowser
* @param mb pointer on MapBrowser to use (default is map itself)
*/
void setBrowser(MapBrowser* mb) { m_currentBrowser = mb; }
// /**
// * @brief set the current MapBrowser
// * @param mb pointer on MapBrowser to use (default is map itself)
// */
// void setBrowser(MapBrowser* mb) { m_currentBrowser = mb; }
/****************************************
* RESOLUTION LEVELS MANAGEMENT *
......@@ -692,11 +692,11 @@ public:
* DARTS TRAVERSALS *
****************************************/
Dart realBegin() const;
// Dart realBegin() const;
Dart realEnd() const;
// Dart realEnd() const;
void realNext(Dart& d) const;
// void realNext(Dart& d) const;
/**
......
......@@ -703,7 +703,8 @@ void GenericMap::addEmbedding()
* DARTS TRAVERSALS *
****************************************/
inline Dart GenericMap::realBegin() const
//inline Dart GenericMap::realBegin() const
inline Dart GenericMap::begin() const
{
if (m_isMultiRes)
{
......@@ -719,7 +720,8 @@ inline Dart GenericMap::realBegin() const
return Dart::create(m_attribs[DART].begin()) ;
}
inline Dart GenericMap::realEnd() const
//inline Dart GenericMap::realEnd() const
inline Dart GenericMap::end() const
{
if (m_isMultiRes)
return Dart::create(m_mrattribs.end()) ;
......@@ -727,7 +729,8 @@ inline Dart GenericMap::realEnd() const
return Dart::create(m_attribs[DART].end()) ;
}
inline void GenericMap::realNext(Dart& d) const
//inline void GenericMap::realNext(Dart& d) const
inline void GenericMap::next(Dart& d) const
{
if (m_isMultiRes)
{
......@@ -743,27 +746,27 @@ inline void GenericMap::realNext(Dart& d) const
}
inline Dart GenericMap::begin() const
{
if (m_currentBrowser != NULL)
return m_currentBrowser->begin();
return GenericMap::realBegin();
}
//inline Dart GenericMap::begin() const
//{
// if (m_currentBrowser != NULL)
// return m_currentBrowser->begin();
// return GenericMap::realBegin();
//}
inline Dart GenericMap::end() const
{
if (m_currentBrowser != NULL)
return m_currentBrowser->end();
return GenericMap::realEnd();
}
//inline Dart GenericMap::end() const
//{
// if (m_currentBrowser != NULL)
// return m_currentBrowser->end();
// return GenericMap::realEnd();
//}
inline void GenericMap::next(Dart& d) const
{
if (m_currentBrowser != NULL)
m_currentBrowser->next(d);
else
realNext(d);
}
//inline void GenericMap::next(Dart& d) const
//{
// if (m_currentBrowser != NULL)
// m_currentBrowser->next(d);
// else
// realNext(d);
//}
//inline Dart GenericMap::begin() const
//{
......
/*******************************************************************************
* 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 MAPBROWSER_H_
#define MAPBROWSER_H_
#include "Topology/generic/dart.h"
#include "Topology/generic/attribmap.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/autoAttributeHandler.h"
namespace CGoGN
{
/**
* Browser that traverses all darts and jumps over
* those not selected by the selector
*/
class MapBrowserSelector : public MapBrowser
{
protected:
AttribMap& m_map ;
const FunctorSelect* m_selector ;
public:
MapBrowserSelector(AttribMap& m, const FunctorSelect& fs);
~MapBrowserSelector();
Dart begin() const;
Dart end() const;
void next(Dart& d) const;
} ;
/**
* Browser that traverses a "submap" stored in a
* linked list (an attribute of dart orbit)
* It inherits from FunctorType to allow the use in
* a foreach_cell which adds darts in the list
*/
class MapBrowserLinked : public MapBrowser, public FunctorType
{
protected:
// The browsed map
AttribMap& m_map ;
// The table attributes of links storing the linking
// The boolean autoAttribute is set if this attribute is managed by the browser
bool autoAttribute ;
DartAttribute<Dart> m_links ;
Dart m_first ;
Dart m_end ;
public:
MapBrowserLinked(AttribMap& m);
MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links);
MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links, Dart first, Dart end);
~MapBrowserLinked();
DartAttribute<Dart>& getLinkAttr();
void clear();
Dart begin() const;
Dart end() const;
void next(Dart& d) const;
void pushFront(Dart d);
void pushBack(Dart d);
void popFront();
void addSelected(const FunctorSelect& fs);
// operator() for use of foreach_cell
bool operator()(Dart d);
void append(MapBrowserLinked& mbl);
} ;
} // namespace CGoGN
#include "Topology/generic/mapBrowser.hpp"
#endif /* MAPBROWSER_H_ */
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
namespace CGoGN
{
inline MapBrowserSelector::MapBrowserSelector(AttribMap& m, const FunctorSelect& fs) :
m_map(m)
{
m_selector = fs.copy();
}
inline MapBrowserSelector::~MapBrowserSelector()
{
delete m_selector;
}
inline Dart MapBrowserSelector::begin() const
{
Dart d = m_map.realBegin() ;
while ( (d != m_map.realEnd()) && !m_selector->operator()(d) )
m_map.realNext(d);
return d;
}
inline Dart MapBrowserSelector::end() const
{
return m_map.realEnd() ;
}
inline void MapBrowserSelector::next(Dart& d) const
{
do
{
m_map.realNext(d) ;
}
while ( (d != m_map.realEnd()) && !m_selector->operator()(d) ) ;
}
inline MapBrowserLinked::MapBrowserLinked(AttribMap& m) :
m_map(m), autoAttribute(true), m_first(NIL), m_end(NIL)
{
m_links = m.addAttribute<Dart, DART>("") ;
}
inline MapBrowserLinked::MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links) :
m_map(m), autoAttribute(false), m_links(links), m_first(NIL), m_end(NIL)
{
}
inline MapBrowserLinked::MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links, Dart first, Dart end) :
m_map(m), autoAttribute(false), m_links(links), m_first(first), m_end(end)
{
}
inline MapBrowserLinked::~MapBrowserLinked()
{
if (autoAttribute)
m_map.removeAttribute(m_links) ;
}
inline DartAttribute<Dart>& MapBrowserLinked::getLinkAttr()
{
return m_links;
}
inline void MapBrowserLinked::clear()
{
m_first = NIL ;
m_end = NIL ;
}
inline Dart MapBrowserLinked::begin() const
{
return m_first ;
}
inline Dart MapBrowserLinked::end() const
{
return NIL ;
}
inline void MapBrowserLinked::next(Dart& d) const
{
assert(d != NIL) ;
d = m_links[d] ;
}
inline void MapBrowserLinked::pushFront(Dart d)
{
assert(d != NIL) ;
m_links[d] = m_first ;
m_first = d ;
if (m_end == NIL) // empty list
m_end = d ;
}
inline void MapBrowserLinked::pushBack(Dart d)
{
assert(d != NIL) ;
m_links[d] = NIL ;
if (m_first == NIL) // empty list
{
m_first = d ;
m_end = d ;
}
else
{
m_links[m_end] = d ;
m_end = d ;
}
}
inline void MapBrowserLinked::popFront()
{
if (m_first == m_end) // one element or empty list
{
m_first = NIL ;
m_end = NIL ;
}
else m_first = m_links[m_first] ;
}
inline void MapBrowserLinked::addSelected(const FunctorSelect& fs)
{
for (Dart d = m_map.begin() ; d != m_map.end() ; m_map.next(d))
{
if (fs(d))
// pushFront(d) ;
pushBack(d); // better tot use push_back for memory access
}
}
// operator() for use of foreach_cell
inline bool MapBrowserLinked::operator()(Dart d)
{
pushFront(d) ;
return false ;
}
inline void MapBrowserLinked::append(MapBrowserLinked& mbl)
{
// nothing to append
if (mbl.m_end == NIL)
return;
if (m_end == NIL)
{
m_first = mbl.m_first;
m_end = mbl.m_end;
return;
}
m_links[m_end] = mbl.m_first;
m_end = mbl.m_end;
}
} // namespace CGoGN
......@@ -108,7 +108,7 @@ GenericMap::GenericMap() : m_nbThreads(1)
if (m_isMultiRes)
initMR() ;
m_currentBrowser = NULL;
// m_currentBrowser = NULL;
}
GenericMap::~GenericMap()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment