void GLSLShader::updateCurrentMatrices() { glm::mat4 model(currentModelView()); model *= currentTransfo(); currentPMV() = currentProjection() * model; currentNormalMatrix() = glm::inverseTranspose(model); for(std::set< std::pair<void*, GLSLShader*> >::iterator it = m_registeredShaders->begin(); it != m_registeredShaders->end(); ++it) it->second->updateMatrices(currentProjection(), model, currentPMV(), currentNormalMatrix()); }
void GLSLShader::updateAllFromGLMatrices() { GLdouble modelview[16]; GLdouble projection[16]; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glm::mat4& model = currentModelView(); glm::mat4& proj = currentProjection(); for (unsigned int i = 0; i < 4; ++i) { for (unsigned int j = 0; j < 4; ++j) { proj[i][j] = float(projection[4*i+j]); model[i][j] = float(modelview[4*i+j]); } } model = currentTransfo() * model; currentPMV() = proj * model; currentNormalMatrix() = glm::inverseTranspose(model); for(std::set< std::pair<void*, GLSLShader*> >::iterator it = m_registeredShaders->begin(); it != m_registeredShaders->end(); ++it) it->second->updateMatrices(proj, model, currentPMV(), currentNormalMatrix()); }
int ViewportParams::polarity() const { // For mercator this just gives the extreme latitudes // instead of the actual poles but it works fine as well: GeoDataCoordinates northPole( 0.0, +currentProjection()->maxLat() ); GeoDataCoordinates southPole( 0.0, -currentProjection()->maxLat() ); bool globeHidesN, globeHidesS; qreal x; qreal yN, yS; currentProjection()->screenCoordinates( northPole, this, x, yN, globeHidesN ); currentProjection()->screenCoordinates( southPole, this, x, yS, globeHidesS ); int polarity = 0; // case of the flat map: if ( !globeHidesN && !globeHidesS ) { if ( yN < yS ) { polarity = +1; } if ( yS < yN ) { polarity = -1; } } else { if ( !globeHidesN && yN < height() / 2 ) { polarity = +1; } if ( !globeHidesN && yN > height() / 2 ) { polarity = -1; } if ( !globeHidesS && yS > height() / 2 ) { polarity = +1; } if ( !globeHidesS && yS < height() / 2 ) { polarity = -1; } } return polarity; }
void milxQtDiffusionTensorModel::colourByDirection() { vtkSmartPointer<vtkPolyData> currentMesh = model.Result(); typedef double projectionType; ///Determine colours based on axes directions vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New(); scalars->SetNumberOfComponents(3); scalars->SetNumberOfTuples(currentMesh->GetNumberOfPoints()); scalars->SetName("Fibre Colours"); scalars->FillComponent(0, 0); scalars->FillComponent(1, 0); scalars->FillComponent(2, 0); vtkSmartPointer<vtkFloatArray> projections = vtkSmartPointer<vtkFloatArray>::New(); projections->SetNumberOfComponents(3); projections->SetNumberOfTuples(currentMesh->GetNumberOfPoints()); projections->SetName("Fibre Projections"); projections->FillComponent(0, 0.0); projections->FillComponent(1, 0.0); projections->FillComponent(2, 0.0); emit working(-1); if(currentMesh->GetNumberOfLines() == 0) { printInfo("No lines in model. Computing colours for mesh."); ///Use the dot product in each axis for(size_t j = 0; j < 3; j ++) { projectionType axis[3] = {0.0, 0.0, 0.0}; axis[j] = 1.0; cout << "Computing toward axis " << j << endl; ///Colour based on each of the gradient values in that direction for(vtkIdType k = 0; k < currentMesh->GetNumberOfPoints(); k ++) { coordinate currentProjection(projections->GetTuple3(k)), position(currentMesh->GetPoint(k)); projectionType projection = vtkMath::Dot(axis, position.data_block()); //project to axis being done, currentProjection[j] = projection; //projection in each direction projections->SetTuple3(k, currentProjection[0], currentProjection[1], currentProjection[2]); } } ///Colour based on each of the gradient values in that direction for(vtkIdType k = 0; k < currentMesh->GetNumberOfPoints(); k ++) { coordinate currentProjection(projections->GetTuple3(k)); coordinate currentProjSquared = element_product(currentProjection, currentProjection); projectionType maxProjection = currentProjSquared.max_value(); currentProjSquared /= maxProjection; unsigned char colourOfPoint[3] = {0, 0, 0}; colourOfPoint[0] = static_cast<unsigned char>( currentProjSquared[0]*255.0 ); colourOfPoint[1] = static_cast<unsigned char>( currentProjSquared[1]*255.0 ); colourOfPoint[2] = static_cast<unsigned char>( currentProjSquared[2]*255.0 ); scalars->SetTupleValue(k, colourOfPoint); } currentMesh->GetPointData()->SetVectors(projections); currentMesh->GetPointData()->SetScalars(scalars); } else { printInfo("Re-colouring lines by axes directions"); //Ensure lines done properly so can colour appropriately currentMesh->GetLines()->InitTraversal(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New(); std::vector<vtkIdType> trackLengths; for(vtkIdType j = 0; j < currentMesh->GetNumberOfLines(); j ++) { currentMesh->GetLines()->GetNextCell(idList); trackLengths.push_back(idList->GetNumberOfIds()); for(vtkIdType pointId = 0; pointId < idList->GetNumberOfIds(); pointId ++) { // std::cout << idList->GetId(pointId) << " "; double position[3]; currentMesh->GetPoint(idList->GetId(pointId), position); points->InsertNextPoint(position); } } //Re-stitch lines together vtkIdType step = 0; vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); for(size_t j = 0; j < trackLengths.size(); j ++) { for(vtkIdType k = step; k < trackLengths[j]-1; k ++) { vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New(); line->GetPointIds()->SetId(0, k); line->GetPointIds()->SetId(1, k+1); lines->InsertNextCell(line); } qDebug() << trackLengths[j] << endl; step += trackLengths[j]; } vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New(); //Add the points to the dataset linesPolyData->SetPoints(points); //Add the lines to the dataset linesPolyData->SetLines(lines); linesPolyData->Modified(); model.SetInput(linesPolyData); } emit done(-1); generateModel(); }