void ViewProviderMeshNode::showOpenEdges(bool show)
{
#if 1
  if ( show ) {
    pcOpenEdge = new SoSeparator();
    pcOpenEdge->addChild(pcLineStyle);
    pcOpenEdge->addChild(pOpenColor);

    const Mesh::Feature* meshFeature = dynamic_cast<Mesh::Feature*>(pcObject);
    MeshGui::SoFCMeshOpenEdge* mesh = new MeshGui::SoFCMeshOpenEdge();
    mesh->setMesh(meshFeature->Mesh.getValuePtr());
    pcOpenEdge->addChild(mesh);
    
    // add to the highlight node
    pcHighlight->addChild(pcOpenEdge);
  } else if (pcOpenEdge) {
    // remove the node and destroy the data
    pcHighlight->removeChild(pcOpenEdge);
    pcOpenEdge = 0;
  }
#else
  if ( show ) {
    pcOpenEdge = new SoSeparator();
    pcOpenEdge->addChild(pcLineStyle);
    pcOpenEdge->addChild(pOpenColor);
    SoCoordinate3* points = new SoCoordinate3();
    pcOpenEdge->addChild(points);
    SoLineSet* lines = new SoLineSet();
    pcOpenEdge->addChild(lines);
    // add to the highlight node
    pcHighlight->addChild(pcOpenEdge);

    // Build up the array of border points
    int index=0;
    const MeshCore::MeshKernel& rMesh = dynamic_cast<Mesh::Feature*>(pcObject)->getMesh();
    const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets();
    const MeshCore::MeshPointArray& rPoint = rMesh.GetPoints();

    // Count number of open edges first
    int ctEdges=0;
    for ( MeshCore::MeshFacetArray::_TConstIterator jt = rFaces.begin(); jt != rFaces.end(); ++jt ) {
      for ( int i=0; i<3; i++ ) {
        if ( jt->_aulNeighbours[i] == ULONG_MAX ) {
          ctEdges++;
        }
      }
    }

    // disable internal notification for speedup
    points->enableNotify(false);
    lines->enableNotify(false);

    points->point.setNum(2*ctEdges);
    lines->numVertices.setNum(ctEdges);
    for ( MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it ) {
      for ( int i=0; i<3; i++ ) {
        if ( it->_aulNeighbours[i] == ULONG_MAX ) {
          const MeshCore::MeshPoint& cP0 = rPoint[it->_aulPoints[i]];
          const MeshCore::MeshPoint& cP1 = rPoint[it->_aulPoints[(i+1)%3]];
          points->point.set1Value(index++, cP0.x, cP0.y, cP0.z);
          points->point.set1Value(index++, cP1.x, cP1.y, cP1.z);
          lines->numVertices.set1Value(index/2-1,2);
        }
      }
    }

    // enable notification
    points->enableNotify(true);
    lines->enableNotify(true);
    points->touch();
    lines->touch();
  } else {
    // remove the node and destroy the data
    pcHighlight->removeChild(pcOpenEdge);
    pcOpenEdge = 0;
  }
#endif
}
Esempio n. 2
0
static SoCallbackAction::Response
processNodesCB(void *userData, SoCallbackAction *ca, const SoNode *node)
{
#ifdef DEBUG
    cerr << "The node is of type " 
	 << node->getTypeId().getName().getString() << endl;
#endif

    if (node->isOfType(SoShape::getClassTypeId())) {
	SbPList *data_list = (SbPList *) userData;

	OSUObjectData *data = new OSUObjectData;
	data_list->append((void *) data);
	data->shape = node->copy();
	data->shape->ref();
	SoVertexShape* vertShape = (SoVertexShape *)data->shape;

	SoState* state = ca->getState();
	SoLazyElement* le = SoLazyElement::getInstance(state);
	le->print(stderr);

	int sIndex = 0;
	if (node->isOfType(SoVertexShape::getClassTypeId())) {
#ifdef DEBUG
	    cerr << "     Found a Vertex Shape!\n";
#endif
	    const SoCoordinateElement* ce;
	    ce = SoCoordinateElement::getInstance(state);

	    //  If we don't start at 0 then why copy those vertices.
	    //  We could also check to see just how many points we use and 
	    //  remove those as well, but that will take a bit more work.

	    if (vertShape->isOfType(SoNonIndexedShape::getClassTypeId())){
		sIndex = ((SoNonIndexedShape*)vertShape)->startIndex.getValue();
		((SoNonIndexedShape*)vertShape)->startIndex.setValue(0);

	    }
	    if (ce->is3D() ){   // It's 3D
#ifdef DEBUG
		cerr << "  There are " << ce->getNum() << " 3D coords\n";
#endif
		SoCoordinate3 *Ps = new SoCoordinate3;
		Ps->point.setValues(0, ce->getNum() - sIndex,&ce->get3(sIndex));
		Ps->ref();
		data->points = (SoNode *) Ps;
	    } else {  // It's 4D
#ifdef DEBUG
		cerr << "  There are " << ce->getNum() << " 4D coords\n";
#endif
		SoCoordinate4 *Ps = new SoCoordinate4;
		Ps->point.setValues(0, ce->getNum() - sIndex,&ce->get4(sIndex));
		Ps->ref();
		data->points = (SoNode *) Ps;
	    }
	    const SoNormalElement* ne = SoNormalElement::getInstance(state);
	    SoNormalBinding::Binding nb = 
		(SoNormalBinding::Binding)SoNormalBindingElement::get(state);
	    int startNrmIndex = 0;
	    if (ne != NULL && ne->getNum()>0){
		// vp->normalBinding.setValue(nb);
	    
		if (nb == SoNormalBinding::PER_VERTEX){
		    startNrmIndex = sIndex;
		}
		data->normals = new SoNormal;
		data->normals->ref();
		data->normals->vector.setValues(0, (ne->getNum())-startNrmIndex, 
		                               &ne->get(startNrmIndex));    
	    }
	}  // End vertex shapes

	// If there are texture coordinates in the state,
	//put them into the vertex property node.
     
    
	int startTxtIndex = 0;
	SoTextureCoordinateBinding::Binding tcb = 
	    (SoTextureCoordinateBinding::Binding)
		SoTextureCoordinateBindingElement::get(state);
	if (tcb == SoTextureCoordinateBinding::PER_VERTEX)
	    startTxtIndex = sIndex;
	const SoTextureCoordinateElement* tce = 
	    SoTextureCoordinateElement::getInstance(state);
	if (tce->getType() == SoTextureCoordinateElement::EXPLICIT &&
	    (tce->getNum() > 0 )){
	    data->texture_points = new SoTextureCoordinate2;
	    data->texture_points->ref();
	    data->texture_points->point.setValues(0, tce->getNum() - startTxtIndex, 
	                          	  &tce->get2(startTxtIndex));
	    // vp->texCoord.setValues(0, tce->getNum() - startTxtIndex, 
	//	&tce->get2(startTxtIndex));
	}
	SbVec2s size;
	int numcomponents, wrapS, wrapT, model;
	SbColor blendColor(0,0,0);

	const unsigned char *timage = SoTextureImageElement::get(state, size, numcomponents, wrapS, wrapT, model, blendColor);

	if (timage) {
	    data->texture = new SoTexture2;
	    data->texture->ref();
	    // data->texture->filename.setValue(tfilename);
	    // data->texture->image.setValue(size, numcomponents, timage);
	    timage = ca->getTextureImage(size, numcomponents);
	    data->texture->image.setValue(size, numcomponents, timage);
	    data->texture->wrapS = wrapS;
	    data->texture->wrapT = wrapT;
	    data->texture->model = model;
	    data->texture->blendColor.setValue(blendColor);
	}
 
        data->complexity = new SoComplexity;
	data->complexity->ref();
	data->complexity->value = ca->getComplexity();
	data->complexity->type = ca->getComplexityType();

	data->draw_style = new SoDrawStyle;
	data->draw_style->ref();
	data->draw_style->style = ca->getDrawStyle();
	data->draw_style->pointSize = ca->getPointSize();
	data->draw_style->lineWidth = ca->getLineWidth();
	data->draw_style->linePattern = ca->getLinePattern();


#ifdef DEBUG
	cerr << "The model matrix is " << ca->getModelMatrix() << endl;
#endif
	SbMatrix const xm = ca->getModelMatrix();

	data->transformation = new SoTransform;
	data->transformation->ref();
	data->transformation->setMatrix(xm);

	SoMaterial *material = new SoMaterial;
	material->ref();
	material->ambientColor = SoLazyElement::getAmbient(state);
        material->diffuseColor = SoLazyElement::getDiffuse(state, 0);
        material->specularColor = SoLazyElement::getSpecular(state);
        material->emissiveColor = SoLazyElement::getEmissive(state);
        material->shininess = SoLazyElement::getShininess(state);
        material->transparency = SoLazyElement::getTransparency(state, 0);
	data->material = material;
    }

    return SoCallbackAction::CONTINUE;
}