//取消选取 void DcGp::DcGpPointCloud::CancelChoosed() { if (!IsChoosed()) { return; } //取消每个点的选取状态 std::fill_n(m_pDcGpPointCloudImpl->m_pointsChoosedState.begin(), Size(), false); //清空每个点的选取颜色 if (HasColors() && GetColorMode() == eTrueLinearColor) { m_pDcGpPointCloudImpl->m_choosedColors = m_pDcGpPointCloudImpl->m_rgbColors; } else if (GetColorMode() == eFalseRangeColor || GetColorMode() == eFalseHeightColor || GetColorMode() == eFalseScalarColor) { m_pDcGpPointCloudImpl->m_choosedColors = m_pDcGpPointCloudImpl->m_scalarColors; } else { PointColor color = {GetTempColor()[0], GetTempColor()[1], GetTempColor()[2]}; std::fill_n(m_pDcGpPointCloudImpl->m_choosedColors.begin(), Size(), color); } }
int main(void) { // Initailize testing data InitializeTestData (); // Add all test data in an array NODE NodeArray[] = {NodeA, NodeB, NodeC, NodeD, NodeE, NodeF}; //The path array count will just have NodeArray count minus 1. // Initialize Path Array. int PathArrayCount = GET_ARRAY_COUNT(NodeArray) -1; PATH ChoosedPath[PathArrayCount]; memset (ChoosedPath, 0, sizeof(ChoosedPath)); while(PathArrayCount--) { int Row = 0, Column = 0; // Initailize pointer PATH PtrPath; //PtrPath = &ChoosedPath[PathArrayCount]; PtrPath.Distance = -1; //for checking // Double for loop for Array for(Row =0; Row< GET_ARRAY_COUNT(NodeArray); Row++) { NODE *Ptr = &NodeArray[Row]; for (Column = 0; Column < Ptr->LinkCount; Column++) { // 現在的值 PATH TmpPath; TmpPath.Distance = Ptr->PtrList[Column].Distance; // 兩個Node Name TmpPath.Node[0] = Ptr; TmpPath.Node[1] = Ptr->PtrList[Column].Node; #if DEBUG_CLOSE printf("TMP %s and %s: %d\n", TmpPath.Node[0].NodeName, TmpPath.Node[1].NodeName, TmpPath.Distance); #endif // Checking if (PtrPath.Distance == -1 || PtrPath.Distance> TmpPath.Distance) { if (!IsChoosed(&TmpPath, ChoosedPath, GET_ARRAY_COUNT(ChoosedPath) ) && !IsReturnToRoot(TmpPath.Node[1], TmpPath.Node[0], ChoosedPath, GET_ARRAY_COUNT(ChoosedPath), NULL) ) { PtrPath = TmpPath; } } } } if (PtrPath.Distance != -1) { memcpy (&ChoosedPath[PathArrayCount], &PtrPath, sizeof (PATH)); printf("===== Ans %s and %s : %d ========= \n", PtrPath.Node[0]->NodeName, PtrPath.Node[1]->NodeName, PtrPath.Distance); } else { // Finish or error. break; } } FreeTestData(); return 0; }
//绘制点云 void DcGp::DcGpPointCloud::DrawMyselfOnly(DcGpDrawContext& context) { //如果数据隐藏,则返回上层数据 if (!IsVisible()) { return; } //是否存在点数据,否则返回上层函数 if (m_pDcGpPointCloudImpl->m_points.empty()) return; //判断是否是绘制三维物体 if (MACRO_Draw3D(context)) { glPushAttrib(GL_ALL_ATTRIB_BITS); if (!m_pDcGpPointCloudImpl->m_generalDrawShader.getProgramIndex()) { //! 初始化一个shader program,用来处理快速渲染时候点隐藏的问题 char* byteGlVersion = (char*)glGetString(GL_VERSION); if (byteGlVersion[0] < '3' ) { return; } else { m_pDcGpPointCloudImpl->SetupGeneralDrawShaders(); } } if (m_pDcGpPointCloudImpl->m_generalDrawShader.getProgramIndex()) { glUseProgram(m_pDcGpPointCloudImpl->m_generalDrawShader.getProgramIndex()); //! 为block量赋值 double matrixProjection[16]; double matrixView[16]; glGetDoublev(GL_PROJECTION_MATRIX, matrixProjection); glGetDoublev(GL_MODELVIEW_MATRIX, matrixView); DCCore::mat4 matPro; DCCore::mat4 matView; for (int i = 0; i != 16; ++i) { matPro.ptr()[i] = matrixProjection[i]; matView.ptr()[i] = matrixView[i]; } DCCore::mat4 pvm = matPro * matView; m_pDcGpPointCloudImpl->m_generalDrawShader.setUniform("pvm", pvm.ptr()); float isSingleColor = 0; m_pDcGpPointCloudImpl->m_generalDrawShader.setUniform("isSingleColor", &isSingleColor); } //获取显示参数 glDrawParameters glParams; GetDrawingParameters(glParams); glParams.showNormals &= bool(MACRO_LightIsEnabled(context)); //是否使用光照 //! 计算纯色值 std::vector<float > singleColor; if (glParams.showColors && IsColorOverriden()) { singleColor.push_back(GetTempColor()[0]); singleColor.push_back(GetTempColor()[1]); singleColor.push_back(GetTempColor()[2]); glParams.showColors = false; } else { singleColor.push_back(context.pointsDefaultCol[0]); singleColor.push_back(context.pointsDefaultCol[1]); singleColor.push_back(context.pointsDefaultCol[2]); } // L.O.D. unsigned numberOfPoints = Size(); unsigned decimStep = 0; if (m_pDcGpPointCloudImpl->m_pointSize != 0) glPointSize((GLfloat)m_pDcGpPointCloudImpl->m_pointSize); //! 渲染绘制,因为为shader传入了可见性变量,所以不管什么情况只要控制传入 //! 顶点、颜色、法向量即可。顶点是不变的,颜色是变化的(纯色、标量色、选取色),法向量是不变的(存在或者不存在) //!开启alpha测试 glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); int sample = 0; //! 1、每帧中顶点不变 glEnableVertexAttribArray(VSShaderLib::VERTEX_COORD_ATTRIB); glVertexAttribPointer(VSShaderLib::VERTEX_COORD_ATTRIB, 3, GL_FLOAT, 0, sample * 3 * sizeof(PointCoordinateType), &(m_pDcGpPointCloudImpl->m_points[0][0])); //! 2、每帧中顶点可见性不变,传递顶点的可见性变量到shader中 glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB1); glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB1, 1, GL_INT, 0, sample * 1 * sizeof(int), &(m_pDcGpPointCloudImpl->m_pointsVisibility[0])); //! 3、确定颜色值怎么选择(只存在纯色、真彩色、标量色三种) if (glParams.showColors) { glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); if (IsChoosed()) { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_rgbColors[0][0])); } } else if (glParams.showScalarField) { glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); if (IsChoosed()) { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_scalarColors[0][0])); } } else { if (IsChoosed()) { float isSingleColor = 0; m_pDcGpPointCloudImpl->m_generalDrawShader.setUniform("isSingleColor", &isSingleColor); glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { //! 纯色处理,由于纯色不是颜色数组,所以采用uniform实现 float isSingleColor = 1; m_pDcGpPointCloudImpl->m_generalDrawShader.setUniform("isSingleColor", &isSingleColor); //!传入纯色值 m_pDcGpPointCloudImpl->m_generalDrawShader.setUniform("singleColor", &singleColor[0]); } } //! 渲染 //glDrawArrays(GL_POINTS, 0, numberOfPoints); //绘制顶点数组时候均采用循环处理,采用数据定长处理,每次处理100000数据 if (GetChunk() > 1) { for (long i = 0; i != GetChunk(); ++i) { if (i == GetChunk()-1) { glDrawArrays(GL_POINTS, DC_CHUNK_COUNT * i, Size() - DC_CHUNK_COUNT * i); } else { glDrawArrays(GL_POINTS, DC_CHUNK_COUNT * i, DC_CHUNK_COUNT); } } } else { glDrawArrays(GL_POINTS, 0, Size()); } glDisableVertexAttribArray(VSShaderLib::VERTEX_COORD_ATTRIB); glDisableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB1); glDisableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); glDisable(GL_ALPHA_TEST); glPopAttrib(); glUseProgram(0); } else if (MACRO_Draw2D(context)) { if (MACRO_Foreground(context) && !context.sfColorScaleToDisplay) { if (IsSfColorbarVisible() && ScalarFieldShown()) { //drawScale(context); AddColorBarInfo(context); } } } //绘制文本 //context._win->Display3DLabel( "Qt", GetPoint(0) + DCVector3D(context.pickedPointsTextShift), DCColor::MAGENTA, QFont()); }
void DcGp::DcGpPointCloud::FastDrawMyselfOnly(DcGpDrawContext& context) { //如果数据隐藏,则返回上层数据 if (!IsVisible()) { return; } //是否存在点数据,否则返回上层函数 if (m_pDcGpPointCloudImpl->m_points.empty()) return; //判断是否是绘制三维物体 if (MACRO_Draw3D(context)) { glPushAttrib(GL_ALL_ATTRIB_BITS); if (!m_pDcGpPointCloudImpl->m_fastDrawShader.getProgramIndex()) { //! 初始化一个shader program,用来处理快速渲染时候点隐藏的问题 char* byteGlVersion = (char*)glGetString(GL_VERSION); if (byteGlVersion[0] < '3' ) { return; } else { m_pDcGpPointCloudImpl->SetupFastDrawShaders(); } } if (m_pDcGpPointCloudImpl->m_fastDrawShader.getProgramIndex()) { glUseProgram(m_pDcGpPointCloudImpl->m_fastDrawShader.getProgramIndex()); //! 为block量赋值 double matrixProjection[16]; double matrixView[16]; glGetDoublev(GL_PROJECTION_MATRIX, matrixProjection); glGetDoublev(GL_MODELVIEW_MATRIX, matrixView); DCCore::mat4 matPro; DCCore::mat4 matView; for (int i = 0; i != 16; ++i) { matPro.ptr()[i] = matrixProjection[i]; matView.ptr()[i] = matrixView[i]; } DCCore::mat4 pvm = matPro * matView; m_pDcGpPointCloudImpl->m_fastDrawShader.setUniform("pvm", pvm.ptr()); float isSingleColor = 0; m_pDcGpPointCloudImpl->m_fastDrawShader.setUniform("isSingleColor", &isSingleColor); } //获取显示参数 glDrawParameters glParams; GetDrawingParameters(glParams); glParams.showNormals &= bool(MACRO_LightIsEnabled(context)); //是否使用光照 //! 计算纯色值 std::vector<float > singleColor; if (glParams.showColors && IsColorOverriden()) { singleColor.push_back(GetTempColor()[0]); singleColor.push_back(GetTempColor()[1]); singleColor.push_back(GetTempColor()[2]); glParams.showColors = false; } else { singleColor.push_back(context.pointsDefaultCol[0]); singleColor.push_back(context.pointsDefaultCol[1]); singleColor.push_back(context.pointsDefaultCol[2]); } // L.O.D. unsigned numberOfPoints = Size(); unsigned sample = 1;//标准的显示全部点 unsigned totalSamplePoints = numberOfPoints; if (numberOfPoints >= DCCore::MAX_FACE_NUM) { sample = static_cast<int>(ceil(static_cast<float>(numberOfPoints) / DCCore::MAX_FACE_NUM)); } if (m_pDcGpPointCloudImpl->m_pointSize != 0) glPointSize((GLfloat)m_pDcGpPointCloudImpl->m_pointSize); //! 渲染绘制,因为为shader传入了可见性变量,所以不管什么情况只要控制传入 //! 顶点、颜色、法向量即可。顶点是不变的,颜色是变化的(纯色、标量色、选取色),法向量是不变的(存在或者不存在) //!开启alpha测试 glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); //! 1、每帧中顶点不变 glEnableVertexAttribArray(VSShaderLib::VERTEX_COORD_ATTRIB); glVertexAttribPointer(VSShaderLib::VERTEX_COORD_ATTRIB, 3, GL_FLOAT, 0, sample * 3 * sizeof(PointCoordinateType), &(m_pDcGpPointCloudImpl->m_points[0][0])); //! 2、每帧中顶点可见性不变,传递顶点的可见性变量到shader中 glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB1); glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB1, 1, GL_INT, 0, sample * 1 * sizeof(int), &(m_pDcGpPointCloudImpl->m_pointsVisibility[0])); //! 3、确定颜色值怎么选择(只存在纯色、真彩色、标量色三种) if (glParams.showColors) { glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); if (IsChoosed()) { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_rgbColors[0][0])); } } else if (glParams.showScalarField) { glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); if (IsChoosed()) { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_scalarColors[0][0])); } } else { if (IsChoosed()) { float isSingleColor = 0; m_pDcGpPointCloudImpl->m_fastDrawShader.setUniform("isSingleColor", &isSingleColor); glEnableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); glVertexAttribPointer(VSShaderLib::VERTEX_ATTRIB2, 3, GL_UNSIGNED_BYTE, 0, sample * 3 * sizeof(ColorType), &(m_pDcGpPointCloudImpl->m_choosedColors[0][0])); } else { //! 纯色处理,由于纯色不是颜色数组,所以采用uniform实现 float isSingleColor = 1; m_pDcGpPointCloudImpl->m_fastDrawShader.setUniform("isSingleColor", &isSingleColor); //!传入纯色值 m_pDcGpPointCloudImpl->m_fastDrawShader.setUniform("singleColor", &singleColor[0]); } } //! 渲染 long lodNum = Size(); if (sample > 1) { float numFloat = static_cast<float >(lodNum) / sample; lodNum = static_cast<unsigned>(floor(numFloat)); } glDrawArrays(GL_POINTS, 0, lodNum); glDisableVertexAttribArray(VSShaderLib::VERTEX_COORD_ATTRIB); glDisableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB1); glDisableVertexAttribArray(VSShaderLib::VERTEX_ATTRIB2); glDisable(GL_ALPHA_TEST); glPopAttrib(); glUseProgram(0); } }