renderExplod.cpp 8.78 KB
Newer Older
1 2 3 4
#include "renderExplod.h"

#include "mapHandler.h"

5 6
namespace CGoGN
{
7

8 9
namespace SCHNApps
{
10

untereiner's avatar
untereiner committed
11 12
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) :
	mh(m),
13 14 15
	facesScaleFactor(1.0f),
	volumesScaleFactor(1.0f),
	renderEdges(false),
untereiner's avatar
untereiner committed
16 17
	renderFaces(true),
	faceStyle(FLAT)
18
{
19

untereiner's avatar
untereiner committed
20 21 22 23 24 25 26 27 28 29 30 31
	m_renderExplod = new Algo::Render::GL2::ExplodeVolumeRender(false, false, false);

	m_renderExplod->setNoClippingPlane();
	m_renderExplod->setExplodeVolumes(1.0f);
	m_renderExplod->setExplodeFaces(1.0f);

	QString positionName;

	QString vec3TypeName = QString::fromStdString(nameOfType(PFP3::VEC3()));

	const AttributeHash& attribs = mh->getAttributesList(VERTEX);
	for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
32
	{
untereiner's avatar
untereiner committed
33
		if(i.value() == vec3TypeName)
34
		{
untereiner's avatar
untereiner committed
35 36
			if(positionName != "position")	// try to select an attribute named "position"
				positionName = i.key();		// or anything else if not found
37 38
		}
	}
untereiner's avatar
untereiner committed
39 40 41 42 43 44 45 46 47 48
	positionAttribute = mh->getAttribute<PFP3::VEC3, VERTEX>(positionName);

	colorAttribute = mh->getAttribute<PFP3::VEC3, VOLUME>("color");

	updateRender();
}

PerMapParameterSet::~PerMapParameterSet()
{
	delete m_renderExplod;
49 50
}

untereiner's avatar
untereiner committed
51 52 53 54 55 56 57 58 59 60 61
void PerMapParameterSet::updateRender()
{
	MapHandler<PFP3>* mh3 = static_cast<MapHandler<PFP3>*>(mh);
	if(mh3 == NULL)
		return;

	PFP3::MAP* m = mh3->getMap();

	//if(!color.isValid())
	m_renderExplod->updateData<PFP3>(*m,positionAttribute);
}
62 63 64

bool RenderExplodPlugin::enable()
{
65
	m_dockTab = new RenderExplodDockTab(m_window, this);
66 67
	addTabInDock(m_dockTab, "RenderExplod");

68 69 70 71
	connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
	connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
	connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));

untereiner's avatar
untereiner committed
72

73 74 75 76 77
	return true;
}

void RenderExplodPlugin::disable()
{
untereiner's avatar
untereiner committed
78
	//delete m_renderExplod;
79 80 81 82 83 84 85 86 87
}

void RenderExplodPlugin::redraw(View* view)
{
	ParameterSet* params = h_viewParams[view];

	const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
	foreach(MapHandlerGen* m, maps)
	{
untereiner's avatar
untereiner committed
88 89 90 91 92 93
		PerMapParameterSet* p = params->perMap[m->getName()];

		p->m_renderExplod->setExplodeFaces(p->facesScaleFactor);
		p->m_renderExplod->setExplodeVolumes(p->volumesScaleFactor);

		if(p->renderEdges)
94
		{
untereiner's avatar
untereiner committed
95 96 97 98 99 100 101 102 103 104
			p->m_renderExplod->drawEdges();
		}
		if(p->renderFaces)
		{
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
			glEnable(GL_LIGHTING);
			glEnable(GL_POLYGON_OFFSET_FILL);
			glPolygonOffset(1.0f, 1.0f) ;
			p->m_renderExplod->drawFaces();
			glDisable(GL_POLYGON_OFFSET_FILL);
105 106 107 108
		}
	}
}

109
void RenderExplodPlugin::viewLinked(View* view, Plugin* plugin)
110
{
111
	if(plugin == this)
112
	{
113 114 115
		ParameterSet* params = new ParameterSet();
		h_viewParams.insert(view, params);
		const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
untereiner's avatar
untereiner committed
116
		foreach(MapHandlerGen* mh, maps)
117
		{
untereiner's avatar
untereiner committed
118 119 120 121
			PerMapParameterSet* p = new PerMapParameterSet(mh);
			registerShader(p->m_renderExplod->shaderFaces());
			registerShader(p->m_renderExplod->shaderLines());
			params->perMap.insert(mh->getName(), p);
122 123 124 125 126 127
		}
		if (!maps.empty())
			changeSelectedMap(view, maps[0]);

		connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
		connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
128

129 130
		if(view->isCurrentView())
			m_dockTab->refreshUI(params);
131
	}
132 133
}

134
void RenderExplodPlugin::viewUnlinked(View* view, Plugin* plugin)
135
{
136 137 138
	if(plugin == this)
	{
		h_viewParams.remove(view);
139

140 141 142
		disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
		disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
	}
143 144 145 146
}

void RenderExplodPlugin::currentViewChanged(View* view)
{
147
	if(isLinkedToView(view))
untereiner's avatar
untereiner committed
148 149 150
	{
		ParameterSet* params = h_viewParams[view];
		changeSelectedMap(view, params->selectedMap);
151
		m_dockTab->refreshUI(h_viewParams[view]);
untereiner's avatar
untereiner committed
152
	}
153 154
}

155
void RenderExplodPlugin::mapLinked(MapHandlerGen* m)
156
{
157
	View* view = static_cast<View*>(QObject::sender());
158
	assert(isLinkedToView(view));
159

untereiner's avatar
untereiner committed
160 161 162 163
	connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));


164
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
165 166 167 168

	PerMapParameterSet* p = new PerMapParameterSet(m);
	registerShader(p->m_renderExplod->shaderFaces());
	registerShader(p->m_renderExplod->shaderLines());
169
	params->perMap.insert(m->getName(), p);
untereiner's avatar
untereiner committed
170

171 172 173 174
	if(params->selectedMap == NULL || params->perMap.count() == 1)
		changeSelectedMap(view, m);
	else
		m_dockTab->refreshUI(params);
175 176
}

177
void RenderExplodPlugin::mapUnlinked(MapHandlerGen* m)
178
{
179
	View* view = static_cast<View*>(QObject::sender());
180
	assert(isLinkedToView(view));
181

untereiner's avatar
untereiner committed
182 183 184 185
	disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));


186 187 188 189 190 191
	ParameterSet* params = h_viewParams[view];
	params->perMap.remove(m->getName());

	if(params->selectedMap == m)
	{
		if(!params->perMap.empty())
192
			changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
193
		else
194 195 196 197 198 199 200
			changeSelectedMap(view, NULL);
	}
	else
		m_dockTab->refreshUI(params);
}


201
void RenderExplodPlugin::changeSelectedMap(View* view, MapHandlerGen* map, bool fromUI)
202 203 204 205 206 207 208 209
{
	ParameterSet* params = h_viewParams[view];

	MapHandlerGen* prev = params->selectedMap;
	params->selectedMap = map;

	if(view->isCurrentView())
	{
210 211
		if(!fromUI)
			m_dockTab->refreshUI(params);
212 213 214 215
		view->updateGL();
	}
}

untereiner's avatar
untereiner committed
216
void RenderExplodPlugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP3::VEC3> attribute, bool fromUI)
217 218
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
219 220 221
	PerMapParameterSet* perMap = params->perMap[map->getName()];
	perMap->positionAttribute = attribute;
	perMap->updateRender();
222 223 224

	if(view->isCurrentView())
	{
225 226
		if(!fromUI)
			m_dockTab->refreshUI(params);
227 228 229 230
		view->updateGL();
	}
}

untereiner's avatar
untereiner committed
231
void RenderExplodPlugin::changeColorAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP3::VEC3> attribute, bool fromUI)
232 233
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
234 235
//	params->perMap[map->getName()].colorAttribute = attribute;
	//perMap->colorAttribute = attribute;
236 237 238

	if(view->isCurrentView())
	{
239 240
		if(!fromUI)
			m_dockTab->refreshUI(params);
241 242 243 244
		view->updateGL();
	}
}

245
void RenderExplodPlugin::changeRenderEdges(View* view, MapHandlerGen* map, bool b, bool fromUI)
246 247
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
248
	params->perMap[map->getName()]->renderEdges = b;
249 250 251

	if(view->isCurrentView())
	{
252 253
		if(!fromUI)
			m_dockTab->refreshUI(params);
254 255 256 257
		view->updateGL();
	}
}

258
void RenderExplodPlugin::changeRenderFaces(View* view, MapHandlerGen* map, bool b, bool fromUI)
259 260
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
261
	params->perMap[map->getName()]->renderFaces = b;
262 263 264

	if(view->isCurrentView())
	{
265 266
		if(!fromUI)
			m_dockTab->refreshUI(params);
267 268 269 270
		view->updateGL();
	}
}

271
void RenderExplodPlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
272 273
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
274
	params->perMap[map->getName()]->facesScaleFactor = i / 50.0;
275 276 277

	if(view->isCurrentView())
	{
278 279
		if(!fromUI)
			m_dockTab->refreshUI(params);
280 281 282 283
		view->updateGL();
	}
}

284
void RenderExplodPlugin::changeVolumesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
285 286
{
	ParameterSet* params = h_viewParams[view];
untereiner's avatar
untereiner committed
287
	params->perMap[map->getName()]->volumesScaleFactor = i / 50.0;
288 289 290

	if(view->isCurrentView())
	{
291 292
		if(!fromUI)
			m_dockTab->refreshUI(params);
293
		view->updateGL();
294 295 296
	}
}

untereiner's avatar
untereiner committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339

void RenderExplodPlugin::attributeModified(unsigned int orbit, QString nameAttr)
{
//	if(orbit == VERTEX)
//	{
//
//		MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(QObject::sender());
//		if(mh == NULL)
//			return;
//
//		VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP3::VEC3, VERTEX>(nameAttr);
//		if(!position.isValid())
//			return;
//
//		PFP3::MAP* map = mh->getMap();
//
//		m_renderExplod->updateData<PFP3>(*map,position);
//
////		if(computeNormalLastParameters.contains(map->getName()))
////		{
////			ComputeNormalParameters& params = computeNormalLastParameters[map->getName()];
////			if(params.positionName == nameAttr && params.autoUpdate)
////				computeNormal(map->getName(), params.positionName, params.normalName);
////		}
//	}
}

void RenderExplodPlugin::connectivityModified()
{
//	MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(QObject::sender());
//	if(mh == NULL)
//		return;
//
//	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP3::VEC3, VERTEX>("position");
//	if(!position.isValid())
//		return;
//
//	PFP3::MAP* map = mh->getMap();
//
//	m_renderExplod->updateData<PFP3>(*map,position);

}

340 341 342 343 344
#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderExplodPlugin, RenderExplodPlugin)
#else
Q_EXPORT_PLUGIN2(RenderExplodPluginD, RenderExplodPlugin)
#endif
345 346 347 348

} // namespace SCHNApps

} // namespace CGoGN