linearTest.h 5.94 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

#include "Utils/glutwin_atb.h"

29
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include "Topology/map/map2.h"

#include "Algo/Export/export.h"
#include "Algo/Import/import.h"

#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/curvature.h"
#include "Algo/Geometry/laplacian.h"

#include "Algo/LinearSolving/basic.h"

#include "Algo/Selection/raySelector.h"

#include "Topology/generic/ecell.h"

#include "Algo/Render/map_glRender.h"
#include "Algo/Render/vbo_MapRender.h"

#include "OpenNL/linear_solver.h"
#include "OpenNL/sparse_matrix.h"
#include "OpenNL/full_vector.h"
#ifdef WITH_CUDA
#include "CNC/cnc_sparse_matrix.h"
#include "CNC/cnc_arrays.h"
#endif


using namespace CGoGN ;


60
struct PFP: public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62
{
	// definition of the map
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 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 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
	typedef Map2 MAP;
};


typedef PFP::MAP MAP;


MAP myMap ;
SelectorTrue allDarts;

unsigned int skipCount = 0 ;

typedef CPULinearSolverTraits< SparseMatrix<double>, FullVector<double> > CPUSolverTraits ;

#ifdef WITH_CUDA
typedef GPULinearSolverTraits< CNCSparseMatrix, CNCArray1d<float> > GPUSolverTraits ;
#endif

class MyGlutWin : public Utils::GlutWin_ATB
{
public:
	TwBar* viewer_bar ;

	enum renderMode { FLAT, GOURAUD, PHONG, VERTICES, NORMAL, CURVATURE_DIRECTIONS } ;

	Geom::Vec4f colDif ;
	Geom::Vec4f colSpec ;
	Geom::Vec4f colClear ;
	Geom::Vec4f colNormal ;

	float shininess ;

	Geom::Vec3f gPosObj ;
	float gWidthObj ;
	float normalBaseSize ;
	float normalScaleFactor ;
	float faceShrinkage ;

	int renderStyle ;
	bool renderObject ;
	bool renderLines ;
	bool renderNormals ;

	enum curvType { MEAN, GAUSSIAN } ;

	bool showCurvature ;
	bool showCurvatureDirections ;
	int curvatureType ;
	int curvatureDir ;
	float curvMultiplicator ;
	float smoothAmount ;

	AttributeHandler<unsigned int> vIndex ;
	PFP::TVEC3 position ;
	PFP::TVEC3 normal ;
	PFP::TVEC3 diffCoord ;
	PFP::TREAL k1 ;
	PFP::TREAL k2 ;
	PFP::TVEC3 K1 ;
	PFP::TVEC3 K2 ;
	AttributeHandler<Geom::Vec4f> color ;

125
	Algo::Render::VBO::MapRender_VBO* vbo_render ;
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	GLuint dl_norm ;

	unsigned int nb_vertices ;

	bool def_locked, def_handle ;
	bool selecting ;
	float select_area ;
	bool deselecting ;
	bool dragging ;
	CellMarker lockingMarker, handleMarker ;
	std::vector<unsigned int> locked_vertices ;
	std::vector<unsigned int> handle_vertices ;

	enum solvType { ITERATIVE, DIRECT } ;
	int solverType ;
#ifdef WITH_CUDA
	bool gpuSolver ;
#endif
	LinearSolver<CPUSolverTraits>* solver ;

	MyGlutWin(int* argc, char **argv, int winX, int winY) ;

	void setSolverType(int t) {
		solverType = t ;
		if(solverType == DIRECT)
			solver->set_direct(true) ;
		else
			solver->set_direct(false) ;
	}
	int getSolverType() { return solverType ; }

	void init() ;
	void initGUI() ;

	void myRedraw() ;
	void myKeyboard(unsigned char keycode, int x, int y) ;
	void myMouse(int button, int state, int x, int y) ;
	void myMotion(int x, int y) ;

	void updateVBOdata(int upType, bool recompute = true) ;
	void initDLNormals() ;
	void render(int renderMode) ;

//	void selectVertices(PFP::MAP::Dart d, float dist) ;
	void selectVertex(Dart d) ;
	void deselectVertex(Dart d) ;
	void deselectAllVertices() ;

	void smooth() ;
	void smoothCurvature() ;
	void lsm() ;
	void matchDiffCoord(bool keepMatrix) ;
} ;

template<typename PFP, class SOLVER_TRAITS>
class FunctorMatrixRowDiffCoord : public FunctorMap<typename PFP::MAP>
{
protected:
	LinearSolver<SOLVER_TRAITS>* solver ;
	const typename PFP::TVEC3& diffCoordTable ;
	AttributeHandler<unsigned int>& indexTable ;
	unsigned int coord ;

public:
	FunctorMatrixRowDiffCoord(MAP& m, LinearSolver<SOLVER_TRAITS>* s, const typename PFP::TVEC3& dc, unsigned int c, AttributeHandler<unsigned int>& idx) :
		FunctorMap<MAP>(m), solver(s), diffCoordTable(dc), indexTable(idx), coord(c)
	{}
	bool operator()(Dart d)
	{
		solver->begin_row() ;
		Dart dd = d ;
		double aii = 0.0 ;
		do
		{
			double aij = 1.0 ;
			aii += aij ;
			solver->add_coefficient(indexTable[this->m_map.phi1(dd)], aij) ;
			dd = this->m_map.alpha1(dd) ;
		} while(dd != d) ;
		solver->add_coefficient(indexTable[d], -aii) ;
		solver->normalize_row() ;
		solver->set_right_hand_side((diffCoordTable[d])[coord]) ;
		solver->end_row() ;
		return false ;
	}
} ;