void Surface_Selection_Plugin::selectedMapBoundingBoxModified() { MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender()); m_selectionRadiusBase = map->getBBdiagSize() / 50.0f; h_parameterSet[map].basePSradius = map->getBBdiagSize() / (std::sqrt(map->getNbOrbits(EDGE))); h_parameterSet[map].verticesScaleFactor = m_dockTab->slider_verticesScaleFactor->value() / 50.0f; }
void Surface_RenderScalar_Plugin::changeScalarVBO(const QString& view, const QString& map, const QString& vbo) { View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { MapParameters& p = h_viewParameterSet[v][m]; Utils::VBO* vbuf = m->getVBO(vbo); p.positionVBO = vbuf; if(vbuf) { MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m); const VertexAttribute<PFP2::REAL, PFP2::MAP>& attr = mh->getAttribute<PFP2::REAL, VERTEX>(QString::fromStdString(vbuf->name())); p.scalarMin = std::numeric_limits<float>::max(); p.scalarMax = std::numeric_limits<float>::min(); for(unsigned int i = attr.begin(); i != attr.end(); attr.next(i)) { p.scalarMin = attr[i] < p.scalarMin ? attr[i] : p.scalarMin; p.scalarMax = attr[i] > p.scalarMax ? attr[i] : p.scalarMax; } } if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_DifferentialProperties_Plugin::computeNormalFromDialog() { QList<QListWidgetItem*> currentItems = m_computeNormalDialog->list_maps->selectedItems(); if(!currentItems.empty()) { const QString& mapName = currentItems[0]->text(); QString positionName = m_computeNormalDialog->combo_positionAttribute->currentText(); QString normalName; if(m_computeNormalDialog->normalAttributeName->text().isEmpty()) normalName = m_computeNormalDialog->combo_normalAttribute->currentText(); else normalName = m_computeNormalDialog->normalAttributeName->text(); bool autoUpdate = (currentItems[0]->checkState() == Qt::Checked); computeNormal(mapName, positionName, normalName, autoUpdate); // create VBO if asked if (m_computeNormalDialog->enableVBO->isChecked()) { MapHandlerGen* mhg = getSCHNApps()->getMap(mapName); if (mhg != NULL) mhg->createVBO(normalName); } } }
void Surface_Radiance_Plugin::changeNormalVBO(const QString& map, const QString& vbo) { MapHandlerGen* m = m_schnapps->getMap(map); if(m) { Utils::VBO* vbuf = m->getVBO(vbo); h_mapParameterSet[m].normalVBO = vbuf; if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } }
void Surface_Render_Plugin::boundingBoxModified() { DEBUG_SLOT(); MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender()); QList<View*> views = map->getLinkedViews(); foreach(View* v, views) { if (h_viewParameterSet.contains(v)) h_viewParameterSet[v][map].basePSradius = map->getBBdiagSize() / (2 * std::sqrt(map->getNbOrbits(EDGE))); } }
void Surface_Selection_Plugin::mouseMove(View* view, QMouseEvent* event) { if(m_selecting) { MapHandlerGen* mh = m_schnapps->getSelectedMap(); const MapParameters& p = h_parameterSet[mh]; if(p.positionAttribute.isValid()) { unsigned int orbit = m_schnapps->getCurrentOrbit(); CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit); if(selector) { QPoint pixel(event->x(), event->y()); qglviewer::Vec orig; qglviewer::Vec dir; view->camera()->convertClickToLine(pixel, orig, dir); // compute coordinates of ray in map Frame qglviewer::Vec orig_inv = mh->getFrame()->coordinatesOf(orig); qglviewer::Vec dir_inv = mh->getFrame()->transformOf(dir); // apply inverse local map transfo glm::vec4 glmRayA = mh->getInverseTransfoMatrix()*glm::vec4(orig_inv.x, orig_inv.y, orig_inv.z, 1.0f); glm::vec4 glmAB = glm::transpose(mh->getInverseTransfoMatrix())*glm::vec4(dir_inv.x, dir_inv.y, dir_inv.z, 1.0f); // put in PFP::VEC3 format PFP2::VEC3 rayA(glmRayA.x, glmRayA.y, glmRayA.z); PFP2::VEC3 AB(glmAB.x, glmAB.y, glmAB.z); PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(mh)->getMap(); switch(orbit) { case VERTEX : { Algo::Selection::vertexRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingVertex); break; } case EDGE : { Algo::Selection::edgeRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingEdge); break; } case FACE : { Algo::Selection::faceRaySelection<PFP2>(*map, p.positionAttribute, rayA, AB, m_selectingFace); break; } } view->updateGL(); } } } }
void Surface_RenderScalar_Plugin::changeExpansion(const QString& view, const QString& map, int i) { View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { h_viewParameterSet[v][m].expansion = i; if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Render_Plugin::changeBackColor(const QString& view, const QString& map, float r, float g, float b) { DEBUG_SLOT(); View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if (v && m) { h_viewParameterSet[v][m].backColor = Geom::Vec4f(r, g, b, 0); if (v->isSelectedView()) { if (v->isLinkedToMap(m)) v->updateGL(); if (m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Render_Plugin::changeRenderBackfaces(const QString& view, const QString& map, bool b) { DEBUG_SLOT(); View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if (v && m) { h_viewParameterSet[v][m].renderBackfaces = b; if (v->isSelectedView()) { if (v->isLinkedToMap(m)) v->updateGL(); if (m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Radiance_Plugin::checkNbVerticesAndExport(Surface_Radiance_Plugin* p, const unsigned int* nbVertices) { if (!p->exportNbVert.empty()) { MapHandlerGen* mhg = p->currentlyDecimatedMap(); if (*nbVertices == p->exportNbVert[p->nextExportIndex]) { std::stringstream exportName; exportName << p->currentlyDecimatedMap()->getName().toStdString() << "_" << (p->currentDecimationHalf() ? "half_" : "full_") << (*nbVertices) << ".ply"; std::cout << "export : " << exportName.str() << std::endl; p->exportPLY(mhg->getName(), "position", "normal", QString::fromStdString(exportName.str())); p->nextExportIndex++; } } }
void Surface_Render_Plugin::changeVerticesScaleFactor(const QString& view, const QString& map, float f) { DEBUG_SLOT(); View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { h_viewParameterSet[v][m].verticesScaleFactor = f; if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Selection_DockTab::vertices_scale_factor_changed(int i) { if (!updating_ui_) { View* view = schnapps_->get_selected_view(); MapHandlerGen* map = schnapps_->get_selected_map(); if (view && map) { MapParameters& p = plugin_->get_parameters(view, map); p.set_vertex_scale_factor(i / 50.0); for (View* view : map->get_linked_views()) view->update(); } } }
void Selection_DockTab::color_changed(int i) { if (!updating_ui_) { View* view = schnapps_->get_selected_view(); MapHandlerGen* map = schnapps_->get_selected_map(); if (view && map) { MapParameters& p = plugin_->get_parameters(view, map); p.set_color(combo_color->color()); for (View* view : map->get_linked_views()) view->update(); } } }
void Surface_RenderScalar_Plugin::changePositionVBO(const QString& view, const QString& map, const QString& vbo) { View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { Utils::VBO* vbuf = m->getVBO(vbo); h_viewParameterSet[v][m].positionVBO = vbuf; if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Selection_Plugin::changeSelectionMethod(const QString& map, unsigned int method) { MapHandlerGen* m = m_schnapps->getMap(map); if(m) { h_parameterSet[m].selectionMethod = SelectionMethod(method); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } View* v = m_schnapps->getSelectedView(); if (v) { if (v->isLinkedToMap(m)) v->updateGL(); } }
void Surface_Render_Plugin::changeFacesStyle(const QString& view, const QString& map, int iStyle) { MapParameters::FaceShadingStyle style = MapParameters::FaceShadingStyle(iStyle); DEBUG_SLOT(); View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { h_viewParameterSet[v][m].faceStyle = style; if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Selection_Plugin::changeSelectedColor( const QString& map, const QString& col) { MapHandlerGen* m = m_schnapps->getMap(map); if (m) { h_parameterSet[m].color = QColor(col); if (m->isSelectedMap()) m_dockTab->updateMapParameters(); View* v = m_schnapps->getSelectedView(); if (v) { if (v->isLinkedToMap(m)) v->updateGL(); } } }
void Surface_Render_Plugin::changeRenderEdges(const QString& view, const QString& map, bool b) { DEBUG_SLOT(); View* v = m_schnapps->getView(view); MapHandlerGen* m = m_schnapps->getMap(map); if(v && m) { h_viewParameterSet[v][m].renderEdges = b; if (b) h_viewParameterSet[v][m].basePSradius = m->getBBdiagSize() / (16 * std::sqrt(m->getNbOrbits(EDGE))); if(v->isSelectedView()) { if(v->isLinkedToMap(m)) v->updateGL(); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } } }
void Surface_Selection_Plugin::changeNormalAttribute(const QString& map, const QString& name) { MapHandlerGen* m = m_schnapps->getMap(map); if(m) { MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m); h_parameterSet[m].normalAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(name); if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } View* v = m_schnapps->getSelectedView(); if (v) { if (v->isLinkedToMap(m)) v->updateGL(); } }
void Selection_DockTab::selected_map_vertex_attribute_added(const QString& name) { updating_ui_ = true; QString vec3_type_name = QString::fromStdString(cgogn::name_of_type(VEC3())); MapHandlerGen* map = schnapps_->get_selected_map(); const MapHandlerGen::ChunkArrayContainer<cgogn::numerics::uint32>* container = map->const_attribute_container(Vertex_Cell); QString attribute_type_name = QString::fromStdString(container->get_chunk_array(name.toStdString())->type_name()); if (attribute_type_name == vec3_type_name) { combo_positionAttribute->addItem(name); combo_normalAttribute->addItem(name); } updating_ui_ = false; }
void Surface_Selection_Plugin::changeVerticesBaseSize(const QString& map, float f) { DEBUG_SLOT(); MapHandlerGen* m = m_schnapps->getMap(map); if (m) { h_parameterSet[m].basePSradius = f; if (m->isSelectedMap()) m_dockTab->updateMapParameters(); } View* v = m_schnapps->getSelectedView(); if (v) { if (v->isLinkedToMap(m)) v->updateGL(); } }
void Surface_Selection_Plugin::clearSelection(const QString& map, unsigned int orbit, const QString& selectorName) { MapHandlerGen* m = m_schnapps->getMap(map); if (m) { CellSelectorGen* selector = m->getCellSelector(orbit, selectorName); if (selector) { selector->clearAll(); } View* v = m_schnapps->getSelectedView(); if (v) { if (v->isLinkedToMap(m)) v->updateGL(); } } }
void Surface_DifferentialProperties_Plugin::attributeModified(unsigned int orbit, QString nameAttr) { if(orbit == VERTEX) { MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender()); if(computeNormalLastParameters.contains(map->getName())) { ComputeNormalParameters& params = computeNormalLastParameters[map->getName()]; if(params.autoUpdate && params.positionName == nameAttr) computeNormal(map->getName(), params.positionName, params.normalName, true); } if(computeCurvatureLastParameters.contains(map->getName())) { ComputeCurvatureParameters& params = computeCurvatureLastParameters[map->getName()]; if(params.autoUpdate && (params.positionName == nameAttr || params.normalName == nameAttr)) computeCurvature( map->getName(), params.positionName, params.normalName, params.KmaxName, params.kmaxName, params.KminName, params.kminName, params.KnormalName, true ); } } }
MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName) { QFileInfo fi(fileName); if(fi.exists()) { MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 2); if(mhg) { MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg); PFP2::MAP* map = mh->getMap(); MeshTablesSurface_Radiance importer(*map); if (!importer.importPLY<Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(fileName.toStdString())) { std::cout << "could not import " << fileName.toStdString() << std::endl; return NULL; } CGoGN::Algo::Surface::Import::importMesh<PFP2>(*map, importer); // get vertex position attribute VertexAttribute<PFP2::VEC3, PFP2::MAP> position = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("position") ; VertexAttribute<PFP2::VEC3, PFP2::MAP> normal = map->getAttribute<PFP2::VEC3, VERTEX, PFP2::MAP>("normal"); mh->registerAttribute(position); mh->registerAttribute(normal); MapParameters& mapParams = h_mapParameterSet[mhg]; mapParams.nbVertices = Algo::Topo::getNbOrbits<VERTEX>(*map); mapParams.radiance = map->getAttribute<Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, VERTEX, PFP2::MAP>("radiance") ; mapParams.radianceTexture = new Utils::Texture<2, Geom::Vec3f>(GL_FLOAT); mapParams.param = map->checkAttribute<Geom::Vec2i, VERTEX, PFP2::MAP>("param"); // create texture unsigned int nbv_nbc = Algo::Topo::getNbOrbits<VERTEX>(*map) * Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>::get_nb_coefs(); unsigned int size = 1; while (size * size < nbv_nbc) size <<= 1; mapParams.radianceTexture->create(Geom::Vec2i(size, size)); // fill texture unsigned int count = 0; foreach_cell<VERTEX>(*map, [&] (Vertex v) { unsigned int i = count / size; unsigned int j = count % size; mapParams.param[v] = Geom::Vec2i(i, j) ; // first index for current vertex for (int l = 0 ; l <= Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>::get_resolution() ; ++l) { for (int m = -l ; m <= l ; ++m) { i = count / size; j = count % size; (*(mapParams.radianceTexture))(i,j) = mapParams.radiance[v].get_coef(l, m); ++count; } } }) ; // resulting texture : SH00_vx0, SH1-1_vx0, ..., SHlm_vx0, SH00_vx1, SH1-1_vx1, ..., SHlm_vx1, etc. // resulting param : param[vxI] points to SH00_vxI // the size of the texture is needed to know where to do the divisions and modulos. mapParams.radianceTexture->update(); // uncomment this line to be able to load multiple objects with different SH basis // (decimation will be unavailable) // map->removeAttribute(mapParams.radiance); mapParams.paramVBO = new Utils::VBO(); mapParams.paramVBO->updateData(mapParams.param); mapParams.radiancePerVertexShader = new Utils::ShaderRadiancePerVertex(Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>::get_resolution()); registerShader(mapParams.radiancePerVertexShader); } this->pythonRecording("importFile", mhg->getName(), fi.baseName()); return mhg; } else return NULL; }
void SurfaceRender_DockTab::refresh_ui() { MapHandlerGen* map = schnapps_->get_selected_map(); View* view = schnapps_->get_selected_view(); if (!map || !view) return; const MapParameters& p = plugin_->get_parameters(view, map); updating_ui_ = true; combo_positionVBO->clear(); combo_positionVBO->addItem("- select VBO -"); combo_normalVBO->clear(); combo_normalVBO->addItem("- select VBO -"); combo_colorVBO->clear(); combo_colorVBO->addItem("- select VBO -"); uint32 i = 1; for (const auto& vbo_it : map->get_vbo_set()) { auto& vbo = vbo_it.second; if (vbo->vector_dimension() == 3) { combo_positionVBO->addItem(QString::fromStdString(vbo->name())); if (vbo.get() == p.get_position_vbo()) combo_positionVBO->setCurrentIndex(i); combo_normalVBO->addItem(QString::fromStdString(vbo->name())); if (vbo.get() == p.get_normal_vbo()) combo_normalVBO->setCurrentIndex(i); combo_colorVBO->addItem(QString::fromStdString(vbo->name())); if (vbo.get() == p.get_color_vbo()) combo_colorVBO->setCurrentIndex(i); ++i; } } check_renderVertices->setChecked(p.get_render_vertices()); slider_vertexScaleFactor->setSliderPosition(p.get_vertex_scale_factor() * 50.0); check_renderEdges->setChecked(p.get_render_edges()); check_renderFaces->setChecked(p.get_render_faces()); check_renderBackFaces->setChecked(p.get_render_backfaces()); radio_flatShading->setChecked(p.get_face_style() == MapParameters::FLAT); radio_phongShading->setChecked(p.get_face_style() == MapParameters::PHONG); check_renderBoundary->setChecked(p.get_render_boundary()); vertex_color_ = p.get_vertex_color(); vertexColorButton->setStyleSheet("QPushButton { background-color:" + vertex_color_.name() + " }"); edge_color_ = p.get_edge_color(); edgeColorButton->setStyleSheet("QPushButton { background-color:" + edge_color_.name() + " }"); front_color_ = p.get_front_color(); frontColorButton->setStyleSheet("QPushButton { background-color:" + front_color_.name() + " }"); bothColorButton->setStyleSheet("QPushButton { background-color:" + front_color_.name() + "}"); back_color_ = p.get_back_color(); backColorButton->setStyleSheet("QPushButton { background-color:" + back_color_.name() + " }"); #ifdef USE_TRANSPARENCY check_useTransparency->setChecked(p.get_transparency_enabled()); slider_transparency->setValue(p.get_transparency_factor()); slider_transparency->setEnabled(p.get_transparency_enabled()); #endif updating_ui_ = false; }