Commit 6982c761 authored by Pierre Kraemer's avatar Pierre Kraemer

colorMap + normal cycles + update BoundingBox

parent 86c7b139
......@@ -185,13 +185,9 @@ void Viewer::importMesh(std::string& filename)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
normalBaseSize = std::min<float>(std::min<float>(tailleX,tailleY),tailleZ) / 50.0f ;
normalBaseSize = bb.diagSize() / 100.0f ;
vertexBaseSize = normalBaseSize * 2.0f ;
if(!normal.isValid())
......@@ -202,7 +198,7 @@ void Viewer::importMesh(std::string& filename)
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
setParamObject(gWidthObj, gPosObj.data()) ;
setParamObject(bb.maxSize(), gPosObj.data()) ;
updateGLMatrices() ;
}
......
......@@ -77,8 +77,8 @@ public:
float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ;
Geom::Vec3f gPosObj ;
float gWidthObj ;
float normalBaseSize ;
float normalScaleFactor ;
float vertexBaseSize ;
......
......@@ -107,6 +107,7 @@ template <typename PFP>
void computeCurvatureVertex_NormalCycles(
typename PFP::MAP& map,
Dart dart,
typename PFP::REAL radius,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles,
......
......@@ -157,19 +157,15 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart
typename PFP::REAL c = n1 * n2 ;
typename PFP::REAL a(0) ;
// the following trick is useful for avoiding NaNs (due to floating point errors)
if (c > 0.5)
a = asin(s) ;
if (c > 0.5) a = asin(s) ;
else
{
if(c < -1)
c = -1 ;
if (s >= 0)
a = acos(c) ;
else
a = -acos(c) ;
if(c < -1) c = -1 ;
if (s >= 0) a = acos(c) ;
else a = -acos(c) ;
}
if (isnan(a))
std::cerr<< "Warning : computeAngleBetweenNormalsOnEdge returns NaN on edge "<< d << "-" << dd << std::endl ;
std::cerr<< "Warning : computeAngleBetweenNormalsOnEdge returns NaN on edge " << d << "-" << dd << std::endl ;
return a ;
}
......
......@@ -42,37 +42,47 @@ class BoundingBox
/* CONSTRUCTORS */
/**********************************************/
// must initialize the bounding box with one first point
BoundingBox(const VEC& p);
BoundingBox() ;
// initialize the bounding box with one first point
BoundingBox(const VEC& p) ;
/**********************************************/
/* ACCESSORS */
/**********************************************/
VEC& min();
VEC& min() ;
const VEC& min() const ;
VEC& max() ;
const VEC& max() const ;
const VEC& min() const;
typename VEC::DATA_TYPE size(unsigned int coord) const ;
VEC& max();
typename VEC::DATA_TYPE maxSize() const ;
const VEC& max() const;
typename VEC::DATA_TYPE minSize() const ;
typename VEC::DATA_TYPE size(unsigned int coord) const;
VEC diag() const ;
VEC center() const;
typename VEC::DATA_TYPE diagSize() const ;
VEC center() const ;
/**********************************************/
/* FUNCTIONS */
/**********************************************/
// add a point to the bounding box
void addPoint(const VEC& p);
void addPoint(const VEC& p) ;
// return true if bb intersects the bounding box
bool intersects(const BoundingBox<VEC>& bb);
bool intersects(const BoundingBox<VEC>& bb) ;
// fusion with the given bounding box
void fusion(const BoundingBox<VEC>& bb);
void fusion(const BoundingBox<VEC>& bb) ;
/**********************************************/
/* STREAM OPERATORS */
......@@ -82,7 +92,6 @@ class BoundingBox
//
// friend std::istream& operator>>(std::istream& in, BoundingBox<VEC>& bb);
friend std::ostream& operator<<(std::ostream& out, const BoundingBox<VEC>& bb)
{
out << bb.min() << " " << bb.max() ;
......@@ -96,11 +105,13 @@ class BoundingBox
}
private:
bool m_initialized ;
VEC m_pMin, m_pMax ;
} ;
}
}
} // namespace Geom
} // namespace CGoGN
#include "bounding_box.hpp"
#endif
......@@ -29,11 +29,18 @@ namespace Geom
{
template <typename VEC>
BoundingBox<VEC>::BoundingBox(const VEC& p) :
m_pMin(p),
m_pMax(p)
BoundingBox<VEC>::BoundingBox() :
m_initialized(false),
m_pMin(0),
m_pMax(0)
{}
template <typename VEC>
BoundingBox<VEC>::BoundingBox(const VEC& p) :
m_initialized(true),
m_pMin(p),
m_pMax(p)
{}
template <typename VEC>
VEC& BoundingBox<VEC>::min()
......@@ -66,6 +73,44 @@ typename VEC::DATA_TYPE BoundingBox<VEC>::size(unsigned int coord) const
return m_pMax[coord] - m_pMin[coord] ;
}
template <typename VEC>
typename VEC::DATA_TYPE BoundingBox<VEC>::maxSize() const
{
typename VEC::DATA_TYPE max = m_pMax[0] - m_pMin[0] ;
for(unsigned int i = 1; i < m_pMax.dimension(); ++i)
{
typename VEC::DATA_TYPE size = m_pMax[i] - m_pMin[i] ;
if(size > max)
max = size ;
}
return max ;
}
template <typename VEC>
typename VEC::DATA_TYPE BoundingBox<VEC>::minSize() const
{
typename VEC::DATA_TYPE min = m_pMax[0] - m_pMin[0] ;
for(unsigned int i = 1; i < m_pMax.dimension(); ++i)
{
typename VEC::DATA_TYPE size = m_pMax[i] - m_pMin[i] ;
if(size < min)
min = size ;
}
return min ;
}
template <typename VEC>
VEC BoundingBox<VEC>::diag() const
{
return m_pMax - m_pMin ;
}
template <typename VEC>
typename VEC::DATA_TYPE BoundingBox<VEC>::diagSize() const
{
return (m_pMax - m_pMin).norm() ;
}
template <typename VEC>
VEC BoundingBox<VEC>::center() const
{
......@@ -80,12 +125,20 @@ VEC BoundingBox<VEC>::center() const
template <typename VEC>
void BoundingBox<VEC>::addPoint(const VEC& p)
{
for(unsigned int i = 0; i < p.dimension(); ++i)
if(!m_initialized)
{
m_pMin = p ;
m_pMax = p ;
}
else
{
if(p[i] < m_pMin[i])
m_pMin[i] = p[i] ;
if(p[i] > m_pMax[i])
m_pMax[i] = p[i] ;
for(unsigned int i = 0; i < p.dimension(); ++i)
{
if(p[i] < m_pMin[i])
m_pMin[i] = p[i] ;
if(p[i] > m_pMax[i])
m_pMax[i] = p[i] ;
}
}
}
......@@ -118,7 +171,6 @@ void BoundingBox<VEC>::fusion(const BoundingBox<VEC>& bb)
}
}
//template <typename VEC>
//friend std::ostream& BoundingBox<VEC>::operator<<(std::ostream& out, const BoundingBox<VEC>& bb)
//{
......@@ -133,8 +185,6 @@ void BoundingBox<VEC>::fusion(const BoundingBox<VEC>& bb)
// return in ;
//}
//end namespace
}
}
} // namespace Geom
} // namespace CGoGN
......@@ -42,7 +42,7 @@ class QTextEdit;
namespace CGoGN
{
namespace CGoGNStream
namespace CGoGNStream
{
/**
......@@ -202,5 +202,4 @@ extern CGoGNStream::Special CGoGNflush;
} // namespace CGoGN
#endif /* CGOGNSTREAM_H_ */
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __COLOR_MAPS_H__
#define __COLOR_MAPS_H__
namespace CGoGN
{
namespace Utils
{
inline Geom::Vec3f color_map_blue_green_red(float x)
{
Geom::Vec3f r(0.0f) ;
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[1] = 2.0f * x;
r[2] = 1.0f - 2.0f * x;
}
else if (x < 1.0f)
{
r[0] = 2.0f * x - 1.0f;
r[1] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_BCGYR(float x)
{
Geom::Vec3f r(0.0f) ;
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.25f)
{
r[0] = 0.0f;
r[1] = 4.0f * x;
r[2] = 1.0f;
}
else if (x < 0.5f)
{
r[0] = 0.0f;
r[1] = 1.0f;
r[2] = 2.0f - 4.0f * x;
}
else if (x < 0.75f)
{
r[0] = 4.0f * x - 2.0f;
r[1] = 1.0f;
r[2] = 0.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 4.0f - 4.0f * x;
r[2] = 0.0f;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_blue_white_red(float x)
{
Geom::Vec3f r(0.0f);
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[0] = 2.0f * x;
r[1] = 2.0f * x;
r[2] = 1.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 2.0f - 2.0f * x;
r[2] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_cyan_white_red(float x)
{
Geom::Vec3f r(0.0f);
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[0] = 2.0f * x;
r[1] = 1.0f;
r[2] = 1.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 2.0f - 2.0f * x;
r[2] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline float scale_expand_within_0_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = (1.0f - cos(M_PI * x)) / 2.0f;
for (int i = -1; i >= n; i--)
x = acos(1.0f - 2.0f * x) / M_PI;
return x;
}
inline float scale_expand_towards_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = sin(x * M_PI / 2.0f);
for (int i = -1; i >= n; i--)
x = asin(x) * 2.0f / M_PI;
return x;
}
inline float scale_to_0_1(float x, float min, float max)
{
return (x - min) / (max - min);
}
inline float scale_and_clamp_to_0_1(float x, float min, float max)
{
float v = (x - min) / (max - min);
return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
}
inline void scale_centering_around_0(float& min, float& max)
{
float new_max = std::max(max, -min);
min = std::min(min, -max);
max = new_max;
}
inline float scale_to_0_1_around_one_half(float x, float min, float max)
{
float ma = std::max(max, -min);
float mi = std::min(min, -max);
return (x - mi) / (ma - mi);
}
} // namespace Utils
} // namespace CGoGN
#endif
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