Ejemplo n.º 1
0
bool PointCloudRenderer::createNodes(SoSeparator *ivRoot, Renderable &renderable)
{

    SoTransform * coord_tran = new SoTransform();
    coord_tran->setName("PointCloudTransform");
    SoCoordinate3 * coord = new SoCoordinate3();
    coord->setName("PointCloudCoordinates");
    SoPointSet * pointSet = new SoPointSet();
    SoDrawStyle * drawStyle = new SoDrawStyle();

    SoMaterial * mat = new SoMaterial();
    mat->setName("PointCloudColorMaterial");
    SoMaterialBinding * matBinding = new SoMaterialBinding();
    matBinding->value = SoMaterialBinding::PER_PART;
    ivRoot->addChild(coord_tran);
    setScale(ivRoot, renderable);
    ivRoot->addChild(coord);
    ivRoot->addChild(mat);
    ivRoot->addChild(matBinding);

    drawStyle->pointSize = 3;
    ivRoot->addChild(drawStyle);

    ivRoot->addChild(pointSet);
    return true;
}
Ejemplo n.º 2
0
SoCallbackAction::Response
SoToVRMLActionP::vrmlpointset_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node)
{
  SoToVRMLActionP * thisp = THISP(closure);

  const SoVRMLPointSet * oldps = coin_assert_cast<const SoVRMLPointSet*>(node);

  SoPointSet * ps = NEW_NODE(SoPointSet, node);
  SoGroup * tail = thisp->get_current_tail();

  SoVRMLColor * color = coin_assert_cast<SoVRMLColor*>(oldps->color.getValue());
  SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate*>(oldps->coord.getValue());

  if (coord) {
    SbName name = coord->getName();
    SoCoordinate3 * newcoord = coin_assert_cast<SoCoordinate3 *> (
      thisp->search_for_node(thisp->vrmlpath->getHead(),
                             name,
                             SoCoordinate3::getClassTypeId())
      );
    if (!newcoord) {
      newcoord = new SoCoordinate3;
      newcoord->setName(name);
      newcoord->point.setValues(0, coord->point.getNum(),
                                coord->point.getValues(0));
    }
    tail->addChild(newcoord);
  }

  if (color) {
    SoMaterial * mat = thisp->find_or_create_material();
    mat->diffuseColor.setValues(0, color->color.getNum(),
                                color->color.getValues(0));
  }

  tail->addChild(ps);
  return SoCallbackAction::CONTINUE;
}
Ejemplo n.º 3
0
SoCallbackAction::Response
SoToVRMLActionP::vrmlils_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node)
{
  SoToVRMLActionP * thisp = THISP(closure);

  const SoVRMLIndexedLineSet * oldils = coin_assert_cast<const SoVRMLIndexedLineSet*>(node);

  if (oldils->coordIndex.getNum() == 0 ||
      oldils->coordIndex[0] < 0) return SoCallbackAction::CONTINUE;

  SoIndexedLineSet * ils = NEW_NODE(SoIndexedLineSet, node);

  SoVRMLColor * color = coin_assert_cast<SoVRMLColor *>(oldils->color.getValue());
  SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate *>(oldils->coord.getValue());
  SoGroup * tail = thisp->get_current_tail();

  SoCoordinate3 * newcoord = NULL;

  if (coord) {
    if (thisp->nodefuse) {
      newcoord = new SoCoordinate3;
    }
    else {
      SbName name = coord->getName();
      newcoord = coin_assert_cast<SoCoordinate3*>(
        thisp->search_for_node(thisp->vrmlpath->getHead(),
                               name,
                               SoCoordinate3::getClassTypeId()));
      if (!newcoord) {
        newcoord = new SoCoordinate3;
        newcoord->setName(name);
        newcoord->point.setValues(0, coord->point.getNum(),
                                  coord->point.getValues(0));
      }
    }
    tail->addChild(newcoord);
  }

  if (color) {
    SoMaterialBinding * bind = new SoMaterialBinding;
    if (oldils->colorPerVertex.getValue()) {
      bind->value = SoMaterialBinding::PER_VERTEX_INDEXED;
    }
    else {
      if (oldils->colorIndex.getNum()) {
        bind->value = SoMaterialBinding::PER_FACE_INDEXED;
      }
      else {
        bind->value = SoMaterialBinding::PER_FACE;
      }
      tail->addChild(bind);
    }

    SoMaterial * mat = thisp->find_or_create_material();
    mat->diffuseColor.setValues(0, color->color.getNum(),
                                color->color.getValues(0));
  }

  if (thisp->nodefuse && coord) {
    SbBSPTree bsp;
    int n = oldils->coordIndex.getNum();
    const int32_t * src = oldils->coordIndex.getValues(0);

    const SbVec3f * c = coord->point.getValues(0);

    ils->coordIndex.setNum(n);
    int32_t * dst = ils->coordIndex.startEditing();

    for (int i = 0; i < n; i++) {
      int idx = src[i];
      if (idx >= 0) {
        dst[i] = bsp.addPoint(c[idx]);
      }
      else dst[i] = -1;
    }
    ils->coordIndex.finishEditing();
    newcoord->point.setValues(0, bsp.numPoints(),
                              bsp.getPointsArrayPtr());

  }
  else {
    ils->coordIndex.setValues(0, oldils->coordIndex.getNum(),
                              oldils->coordIndex.getValues(0));
  }
  if (oldils->colorIndex.getNum()) {
    ils->materialIndex.setValues(0, oldils->colorIndex.getNum(),
                                 oldils->colorIndex.getValues(0));
  }
  tail->addChild(ils);
  return SoCallbackAction::CONTINUE;
}
Ejemplo n.º 4
0
SoCallbackAction::Response
SoToVRMLActionP::vrmlifs_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node)
{
  const SoVRMLIndexedFaceSet * oldifs = coin_assert_cast<const SoVRMLIndexedFaceSet *>(node);

  if (oldifs->coordIndex.getNum() == 0 ||
      oldifs->coordIndex[0] < 0)
    return SoCallbackAction::CONTINUE;

  SoToVRMLActionP * thisp = THISP(closure);

  SoIndexedFaceSet * ifs = NEW_NODE(SoIndexedFaceSet, node);

  SoVRMLColor * color = coin_assert_cast<SoVRMLColor*>(oldifs->color.getValue());
  SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate *>(oldifs->coord.getValue());
  SoVRMLNormal * normal = coin_assert_cast<SoVRMLNormal *>(oldifs->normal.getValue());
  SoVRMLTextureCoordinate * texcoord = coin_assert_cast<SoVRMLTextureCoordinate*>(oldifs->texCoord.getValue());

  SoShapeHints * sh = new SoShapeHints;
  sh->creaseAngle = oldifs->creaseAngle.getValue();
  sh->vertexOrdering = oldifs->ccw.getValue() ?
    SoShapeHints::COUNTERCLOCKWISE : SoShapeHints::CLOCKWISE;
  sh->shapeType = oldifs->solid.getValue() ?
    SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE;
  sh->faceType = oldifs->convex.getValue() ?
    SoShapeHints::CONVEX : SoShapeHints::UNKNOWN_FACE_TYPE;

  SoGroup * tail = thisp->get_current_tail();
  tail->addChild(sh);

  if (coord) {
    SbName name = coord->getName();
    SoCoordinate3 * newcoord = coin_assert_cast<SoCoordinate3*>(
      thisp->search_for_node(thisp->vrmlpath->getHead(),
                             name,
                             SoCoordinate3::getClassTypeId()));
    if (!newcoord) {
      newcoord = new SoCoordinate3;
      newcoord->setName(name);
      newcoord->point.setValues(0, coord->point.getNum(),
                                coord->point.getValues(0));
    }
    tail->addChild(newcoord);
  }

  if (normal) {
    if (oldifs->normalPerVertex.getValue() != TRUE) {
      SoNormalBinding * bind = new SoNormalBinding;
      if (oldifs->normalIndex.getNum()) {
        bind->value = SoMaterialBinding::PER_FACE_INDEXED;
      }
      else bind->value = SoMaterialBinding::PER_FACE;
      tail->addChild(bind);
    }
    SbName name = normal->getName();
    SoNormal * newnormal =
      coin_assert_cast<SoNormal*>(thisp->search_for_node(thisp->vrmlpath->getHead(),
                                         name,
                                         SoNormal::getClassTypeId())
                              );
    if (!newnormal) {
      newnormal = new SoNormal;
      newnormal->setName(name);
      newnormal->vector.setValues(0, normal->vector.getNum(),
                                  normal->vector.getValues(0));
    }
    tail->addChild(newnormal);
  }
  if (color) {
    SoMaterialBinding * bind = new SoMaterialBinding;
    if (oldifs->colorPerVertex.getValue()) {
      bind->value = SoMaterialBinding::PER_VERTEX_INDEXED;
    }
    else {
      if (oldifs->colorIndex.getNum()) {
        bind->value = SoMaterialBinding::PER_FACE_INDEXED;
      }
      else {
        bind->value = SoMaterialBinding::PER_FACE;
      }
      tail->addChild(bind);
    }

    SoMaterial * mat = thisp->find_or_create_material();
    mat->diffuseColor.setValues(0, color->color.getNum(),
                                color->color.getValues(0));
  }
  if (texcoord) {
    SbName name = texcoord->getName();
    SoTextureCoordinate2 * newtc = coin_assert_cast<SoTextureCoordinate2*>(
      thisp->search_for_node(thisp->vrmlpath->getHead(),
                             name,
                             SoTextureCoordinate2::getClassTypeId())
      );
    if (!newtc) {
      newtc = new SoTextureCoordinate2;
      newtc->setName(name);
      newtc->point.setValues(0, texcoord->point.getNum(),
                             texcoord->point.getValues(0));
    }
    tail->addChild(newtc);
  }

  ifs->coordIndex.setValues(0, oldifs->coordIndex.getNum(),
                            oldifs->coordIndex.getValues(0));
  if (oldifs->texCoordIndex.getNum()) {
    ifs->textureCoordIndex.setValues(0, oldifs->texCoordIndex.getNum(),
                                     oldifs->texCoordIndex.getValues(0));
  }
  if (oldifs->colorIndex.getNum()) {
    ifs->materialIndex.setValues(0, oldifs->colorIndex.getNum(),
                                 oldifs->colorIndex.getValues(0));
  }
  if (oldifs->normalIndex.getNum()) {
    ifs->normalIndex.setValues(0, oldifs->normalIndex.getNum(),
                               oldifs->normalIndex.getValues(0));
  }
  tail->addChild(ifs);
  return SoCallbackAction::CONTINUE;
}