colorPerEdgeRender.hpp 3.63 KB
Newer Older
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 50 51 52 53
/*******************************************************************************
* 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 <cmath>

#include "Geometry/vector_gen.h"
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"
#include "Algo/Geometry/centroid.h"

namespace CGoGN
{

namespace Algo
{

namespace Render
{

namespace GL2
{



inline ColorPerEdgeRender::ColorPerEdgeRender():
m_nbEdges(0)
{
}



template<typename PFP, typename ATTRIB>
void ColorPerEdgeRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map,
54
		const VertexAttribute<typename PFP::VEC3>& positions, const ATTRIB& colorPerXXX)
55 56 57
{
	typedef typename PFP::VEC3 VEC3;
	typedef typename PFP::REAL REAL;
58
	typedef Geom::Vec3f VEC3F;
59

60
	std::vector<VEC3F> buffer;
61 62
	buffer.reserve(16384);

63
	std::vector<VEC3F> bufferColors;
64 65
	bufferColors.reserve(16384);

66
	TraversorCell<typename PFP::MAP, EDGE> traEdge(map);
67 68 69

	for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
	{
70 71
		buffer.push_back(PFP::toVec3f(positions[d]);
		bufferColors.push_back(PFP::toVec3f(colorPerXXX[d]));
72
		Dart e = map.phi2(d);
73 74
		buffer.push_back(PFP::toVec3f(positions[e]));
		bufferColors.push_back(PFP::toVec3f(colorPerXXX[e]))	;
75 76 77 78 79 80
	}

	m_nbEdges = buffer.size()/2;

	vboPosition.setDataSize(3);
	vboPosition.allocate(buffer.size());
81 82
	VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr());
	memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3F));
83 84 85 86
	vboPosition.releasePtr();

	vboColor.setDataSize(3);
	vboColor.allocate(bufferColors.size());
87 88
	VEC3F* ptrCol = reinterpret_cast<VEC3F*>(vboColor.lockPtr());
	memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3F));
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	vboColor.releasePtr();
}




inline void ColorPerEdgeRender::draw(Utils::GLSLShader* sh)
{
	sh->enableVertexAttribs();
	glDrawArrays(GL_LINES , 0 , m_nbEdges*2 );
	sh->disableVertexAttribs();
}




}//end namespace VBO

}//end namespace Algo

}//end namespace Render

}//end namespace CGoGN