void Patch4::onUpdate(){ _pFace->update(); //init bezier surface points for(int i=0; i<4; i++){ _K[i]= K(0,i); _K[i+12]= K(2,i); } _K[7] = K(1,1); _K[11] = K(1,2); _K[4] = K(3,1); _K[8] = K(3,2); _K[5] = _K[1] + _K[4] - _K[0]; _K[6] = _K[2] + _K[7] - _K[3]; _K[9] = _K[13] + _K[8] - _K[12]; _K[10] = _K[11] + _K[14] - _K[15]; //bezier surface interpolation for(int j=0; j<N;j++) for(int i=0; i<N; i++){ Point p; for(int bj = 0; bj<4; bj++) for(int bi = 0; bi<4; bi++) p = p + cubicBernstein(bi, i*T)*cubicBernstein(bj, j*T)*_K[bi+bj*4]; _ps[ind(i,j)] = p; } propateNormals(); interpolateNormals(); }
void StaticMesh::init( MeshBufferPtr mesh ) { size_t n_colors; size_t n_normals; m_lineWidth = 2.0; if(mesh) { m_faceNormals = 0; m_normals = mesh->getVertexNormalArray(n_normals); m_colors = mesh->getVertexColorArray(n_colors); m_vertices = mesh->getVertexArray(m_numVertices); m_faces = mesh->getFaceArray(m_numFaces); m_blackColors = new unsigned char[ 3 * m_numVertices ]; for ( size_t i = 0; i < 3 * m_numVertices; i++ ) { m_blackColors[i] = 0; } m_finalized = true; m_visible = true; m_active = true; m_renderMode = 0; m_renderMode |= RenderSurfaces; m_renderMode |= RenderTriangles; m_boundingBox = new BoundingBox<Vertex<float> >; if(!m_faceNormals) { interpolateNormals(); } else { // cout << "Face normals: " << m_faceNormals << endl; } if(!m_colors) { setDefaultColors(); } if(n_colors == 0) { m_colors = ucharArr( new unsigned char[3 * m_numVertices] ); for( int i = 0; i < m_numVertices; ++i ) { m_colors[3 * i] = 0; m_colors[3 * i + 1] = 255; m_colors[3 * i + 2] = 0; } } } }
ccPointCloud* ccGenericMesh::samplePoints( bool densityBased, double samplingParameter, bool withNormals, bool withRGB, bool withTexture, CCLib::GenericProgressCallback* pDlg/*=0*/) { bool withFeatures = (withNormals || withRGB || withTexture); GenericChunkedArray<1,unsigned>* triIndices = (withFeatures ? new GenericChunkedArray<1,unsigned> : 0); CCLib::SimpleCloud* sampledCloud = 0; if (densityBased) { sampledCloud = CCLib::MeshSamplingTools::samplePointsOnMesh(this,samplingParameter,pDlg,triIndices); } else { sampledCloud = CCLib::MeshSamplingTools::samplePointsOnMesh(this,static_cast<unsigned>(samplingParameter),pDlg,triIndices); } //convert to real point cloud ccPointCloud* cloud = 0; if (sampledCloud) { cloud = ccPointCloud::From(sampledCloud); delete sampledCloud; sampledCloud = 0; } if (!cloud) { if (triIndices) triIndices->release(); ccLog::Warning("[ccGenericMesh::samplePoints] Not enough memory!"); return 0; } if (withFeatures && triIndices && triIndices->currentSize() >= cloud->size()) { //generate normals if (withNormals && hasNormals()) { if (cloud->reserveTheNormsTable()) { for (unsigned i=0; i<cloud->size(); ++i) { unsigned triIndex = triIndices->getValue(i); const CCVector3* P = cloud->getPoint(i); CCVector3 N(0,0,1); interpolateNormals(triIndex,*P,N); cloud->addNorm(N); } cloud->showNormals(true); } else { ccLog::Warning("[ccGenericMesh::samplePoints] Failed to interpolate normals (not enough memory?)"); } } //generate colors if (withTexture && hasMaterials()) { if (cloud->reserveTheRGBTable()) { for (unsigned i=0; i<cloud->size(); ++i) { unsigned triIndex = triIndices->getValue(i); const CCVector3* P = cloud->getPoint(i); colorType C[3]={MAX_COLOR_COMP,MAX_COLOR_COMP,MAX_COLOR_COMP}; getColorFromMaterial(triIndex,*P,C,withRGB); cloud->addRGBColor(C); } cloud->showColors(true); } else { ccLog::Warning("[ccGenericMesh::samplePoints] Failed to export texture colors (not enough memory?)"); } } else if (withRGB && hasColors()) { if (cloud->reserveTheRGBTable()) { for (unsigned i=0; i<cloud->size(); ++i) { unsigned triIndex = triIndices->getValue(i); const CCVector3* P = cloud->getPoint(i); colorType C[3] = { MAX_COLOR_COMP, MAX_COLOR_COMP, MAX_COLOR_COMP }; interpolateColors(triIndex,*P,C); cloud->addRGBColor(C); } cloud->showColors(true); } else { ccLog::Warning("[ccGenericMesh::samplePoints] Failed to interpolate colors (not enough memory?)"); } } } //we rename the resulting cloud cloud->setName(getName()+QString(".sampled")); cloud->setDisplay(getDisplay()); cloud->prepareDisplayForRefresh(); //copy 'shift on load' information if (getAssociatedCloud()) { const CCVector3d& shift = getAssociatedCloud()->getGlobalShift(); cloud->setGlobalShift(shift); double scale = getAssociatedCloud()->getGlobalScale(); cloud->setGlobalScale(scale); } if (triIndices) triIndices->release(); return cloud; }