//================================================================
// Function : TexturesExt_Presentation::sampleLand
// Purpose  : 
//================================================================
void TexturesExt_Presentation::sampleTerrain()
{
  TopoDS_Shape aShape;
  if (!loadShape(aShape, "terrain.brep"))
    return;

  // a part of the landscape is textured
  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);

//  TopLoc_Location aLoc;
//  Handle_Geom_Surface aSur = BRep_Tool::Surface(TopoDS::Face(aFaces(1)), aLoc);
//  Standard_Real u1,u2,v1,v2;
//  aSur->Bounds(u1,u2,v1,v2);
//  gp_Pnt aPnt = aSur->Value(u1, v1);
  gp_Pnt aPnt(82100,80300,10940);// point at u1,v1
  // resize and move the shape to the center of the viewer
  
  gp_Trsf aMoveTrsf;
  gp_Ax3 New(gp_Pnt(-30,-30, 0),gp_Dir(0,0,1));
  gp_Ax3 Current(aPnt,gp_Dir(0,0,1));
  aMoveTrsf.SetDisplacement(Current, New);

  gp_Trsf aScaleTrsf;
  aScaleTrsf.SetScale(aPnt,0.0075);

  BRepBuilderAPI_Transform aTransform(aMoveTrsf*aScaleTrsf);

  aTransform.Perform(aFaces(1));
  aShape = aTransform;

  getAISContext()->Display(Texturize(aShape, "terrain.gif"));
}
Exemplo n.º 2
0
bool
SimInterior::processArguments(int argc, const char **argv)
{
   CMDConsole *console = CMDConsole::getLocked();
   if(argc < 1) {
      console->printf("SimInterior: filename.dis [posX posY posZ] [rotX rotY rotZ]");
      return false;
   }

   if(!loadShape(argv[0])) {
      console->printf("SimInterior: unable to load interior shape %s", argv[0]);
      return false;
   }

   if (argc > 1) {
      float f[6];
      memset(f,0,sizeof(f));
      for (int i = 1; i < argc; i++)
         sscanf(argv[i], "%f", &f[i - 1]);
      const float p = float(M_PI/180.0);
      set(EulerF(p*f[3],p*f[4],p*f[5]),Point3F(f[0],f[1],f[2]));
   }

   return true;
}
//================================================================
// Function : TexturesExt_Presentation::sampleBottle
// Purpose  : 
//================================================================
void TexturesExt_Presentation::sampleBottle()
{  
  TopoDS_Shape aShape;
  if (!loadShape(aShape, "bottle.brep")) 
    return;

  // resize and move the shape to the center of the viewer
gp_Trsf aTrsf1, aTrsf2;
aTrsf1.SetScale(gp_Pnt(0,0,0), 0.8);
aTrsf2.SetTranslation(gp_Pnt(0,0,0),gp_Pnt(0,0,-20));
aTrsf1.Multiply(aTrsf2);
BRepBuilderAPI_Transform Transformer(aTrsf1);
Transformer.Perform(aShape);
aShape = Transformer.Shape();

  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);

  // display original shape in shaded display mode
  Handle_AIS_Shape aShapeIO = drawShape(aShape, Graphic3d_NOM_BRASS, Standard_False);
  getAISContext()->SetDisplayMode(aShapeIO, AIS_Shaded, Standard_False);
  // Set increased polygon offset for the main shape to avoid depth collision with textured faces
  aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5);
  DISP(aShapeIO);

  Handle_AIS_TexturedShape aTFace1 = Texturize(aFaces(16), "carrelage1.gif", 1, 1, 3, 2);
  DISP(aTFace1);

  Handle_AIS_TexturedShape aTFace2 = Texturize(aFaces(21), "carrelage1.gif", 1, 1, 3, 2);
  DISP(aTFace2);

  getViewer()->Update();
}
Exemplo n.º 4
0
void
SimInterior::unpackUpdate(Net::GhostManager* /*gm*/,
                          BitStream*         stream)
{
   if (stream->readFlag()) {
      const char *temp = stream->readSTString();

      // If this is the first update, set the filename directly, and let
      //  the onAddNotify handler load the resources, else, load directly...
      //
      if (manager == NULL) {
         setFilename(temp);
      } else {
         loadShape(temp);
      }
   }

   if (stream->readFlag()) {
      Point3F tmpPnt;
      EulerF  tmpAng;
      stream->read(sizeof(tmpPnt), &tmpPnt);
      stream->read(sizeof(tmpAng), &tmpAng);
      set(tmpAng, tmpPnt);
   }
   
   if (stream->readFlag()) {
      
      // We'll limit interiors to 32 states for the moment
      //
      m_currentState = stream->readInt(5);
      if (manager)
         setState(m_currentState);
   }
}
void ShapeView::inspectRead(Inspect *inspect)
{
   char szName[256];

   Parent::inspectRead(inspect);

   inspect->read(IDITG_FM_SHAPE, szName);

   loadShape(szName);
}
Exemplo n.º 6
0
KoOdfCollectionLoader::KoOdfCollectionLoader(const QString& path, QObject* parent)
    : QObject(parent)
{
    m_path = path;
    m_odfStore = 0;
    m_shapeLoadingContext = 0;
    m_loadingContext = 0;
    m_filterManager = 0;

    m_loadingTimer = new QTimer(this);
    m_loadingTimer->setInterval(0);
    connect(m_loadingTimer, SIGNAL(timeout()),
            this, SLOT(loadShape()));
}
Exemplo n.º 7
0
void
SimInterior::inspectRead(Inspect* sd)
{
   Parent::inspectRead(sd);

   // Filename edit
   char newFilename[Inspect::MAX_STRING_LEN + 1];
   sd->read(IDITG_FILENAME, newFilename);
   loadShape(newFilename);

   Point3F     pos;
   Point3F     rot;
   sd->read(IDITG_POSITION, pos);
   sd->read(IDITG_ROTATION, rot);
   
   set(EulerF(rot.x, rot.y, rot.z), pos);
}   
void ShapeView::onWake()
{
   float width, height;

   if (camera)
   {
      // Set up the viewport
      width  = DEFAULT_NEAR_PLANE * tan(DEFAULT_FOV);
      height = (float)extent.y / (float)extent.x * width;

      camera->setWorldViewport(
         RectF(-width, height, width, -height));
      camera->setNearDist(DEFAULT_NEAR_PLANE);
      camera->setFarDist (getFarPlane());
      camera->setScreenViewport(
         RectI(position.x, position.y, 
               position.x + extent.x, position.y + extent.y));

      // Load the shape
      loadShape(gDefaultShapeFile);

      timer.reset();
   }
}
//================================================================
// Function : TexturesExt_Presentation::sampleKitchen
// Purpose  : kitchen with texturized items in it.
//================================================================
void TexturesExt_Presentation::sampleKitchen()
{
  TopoDS_Shape aShape;

  if (!loadShape(aShape, "Kitchen\\Room.brep"))
    return;

  gp_Trsf aTrsf;
  gp_Ax3 NewCoordSystem (gp_Pnt(-1,-1, -1),gp_Dir(0,0,1));
  gp_Ax3 CurrentCoordSystem(gp_Pnt(0,0,0),gp_Dir(0,0,1));
  aTrsf.SetDisplacement(CurrentCoordSystem, NewCoordSystem);
  aShape.Location(TopLoc_Location(aTrsf));

  moveScale(aShape);

  // draw kitchen room whithout one wall (to better see the insides)
  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
  Standard_Integer nbFaces = aFaces.Extent();

  // create a wooden kitchen floor
  // the floor's face will be textured with texture from chataignier.gif
  DISP(Texturize(aFaces(5),"plancher.gif",1,1,2,1));

  // texturize other faces of the room with texture from wallpaper.gif (walls)
  DISP(Texturize(aFaces(1),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(3),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(4),"wallpaper.gif",1,1,8,6));

//  DISP(drawShape(aFaces(1), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(3), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(4), Quantity_NOC_LIGHTPINK, Standard_False));

  // texturize furniture items with "wooden" texture
  if (loadShape(aShape, "Kitchen\\MODERN_Table_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Chair_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i >= 59)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_STEEL, Standard_False));
      else if (i >= 29)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 28)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Exhaust_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_STONE, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i < 145)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 145)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }

  getViewer()->Update();
}
Exemplo n.º 10
0
void KoTextLoader::loadBody(const KoXmlElement &bodyElem, QTextCursor &cursor)
{
    const QTextBlockFormat defaultBlockFormat = cursor.blockFormat();
    const QTextCharFormat defaultCharFormat = cursor.charFormat();

    const QTextDocument *document = cursor.block().document();
    d->styleManager = KoTextDocument(document).styleManager();
    Q_ASSERT(d->styleManager);

    d->changeTracker = KoTextDocument(document).changeTracker();
//    if (!d->changeTracker)
//        d->changeTracker = dynamic_cast<KoChangeTracker *>(d->context.dataCenterMap().value("ChangeTracker"));
//    Q_ASSERT(d->changeTracker);

    kDebug(32500) << "text-style:" << KoTextDebug::textAttributes( cursor.blockCharFormat() );
#if 0
    if ((document->isEmpty()) && (d->styleManager)) {
        QTextBlock block = cursor.block();
        d->styleManager->defaultParagraphStyle()->applyStyle(block);
    }
#endif

    startBody(KoXml::childNodesCount(bodyElem));
    KoXmlElement tag;
    bool usedParagraph = false; // set to true if we found a tag that used the paragraph, indicating that the next round needs to start a new one.
    forEachElement(tag, bodyElem) {
        if (! tag.isNull()) {
            const QString localName = tag.localName();
            if (tag.namespaceURI() == KoXmlNS::text) {
                if (usedParagraph)
                    cursor.insertBlock(defaultBlockFormat, defaultCharFormat);
                usedParagraph = true;
                if (d->changeTracker && localName == "tracked-changes") {
                    d->changeTracker->loadOdfChanges(tag);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-start") {
                    loadChangedRegion(tag, cursor);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-end") {
                    d->currentChangeId = 0;
                    usedParagraph = false;
                } else if (localName == "p") {    // text paragraph
                    loadParagraph(tag, cursor);
                } else if (localName == "h") {  // heading
                    loadHeading(tag, cursor);
                } else if (localName == "unordered-list" || localName == "ordered-list" // OOo-1.1
                           || localName == "list" || localName == "numbered-paragraph") {  // OASIS
                    loadList(tag, cursor);
                } else if (localName == "section") {  // Temporary support (###TODO)
                    loadSection(tag, cursor);
                } else {
                    KoVariable *var = KoVariableRegistry::instance()->createFromOdf(tag, d->context);

                    if (var) {
                        KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*>(cursor.block().document()->documentLayout());
                        if (layout) {
                            KoInlineTextObjectManager *textObjectManager = layout->inlineTextObjectManager();
                            if (textObjectManager) {
                                KoVariableManager *varManager = textObjectManager->variableManager();
                                if (varManager) {
                                    textObjectManager->insertInlineObject(cursor, var);
                                }
                            }
                        }
                    } else {
                        usedParagraph = false;
                        kWarning(32500) << "unhandled text:" << localName;
                    }
                }
            } else if (tag.namespaceURI() == KoXmlNS::draw) {
                loadShape(tag, cursor);
            } else if (tag.namespaceURI() == KoXmlNS::table) {
                if (localName == "table") {
                    loadTable(tag, cursor);
                } else {
                    kWarning(32500) << "unhandled table:" << localName;
                }
#if 0 // TODO commented out for now
                if (localName == "table") {
                    cursor.insertText("\n");
                    cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
                    QTextTable *tbl = cursor.insertTable(1, 1);
                    int rows = 0;
                    int columns = 0;
                    kDebug(32500) << "Table inserted";
                    KoXmlElement tblTag;
                    forEachElement(tblTag, tag) {
                        if (! tblTag.isNull()) {
                            const QString tblLocalName = tblTag.localName();
                            if (tblTag.namespaceURI() == KoXmlNS::table) {
                                if (tblLocalName == "table-column") {
                                    // Do some parsing with the column, see §8.2.1, ODF 1.1 spec
                                    int repeatColumn = tblTag.attributeNS(KoXmlNS::table, "number-columns-repeated", "1").toInt();
                                    columns = columns + repeatColumn;
                                    if (rows > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(1, columns);
                                } else if (tblLocalName == "table-row") {
                                    // Lot of work to do here...
                                    rows++;
                                    if (columns > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(rows, 1);
                                    // Added a row
                                    int currentCell = 0;
                                    KoXmlElement rowTag;
                                    forEachElement(rowTag, tblTag) {
                                        if (!rowTag.isNull()) {
                                            const QString rowLocalName = rowTag.localName();
                                            if (rowTag.namespaceURI() == KoXmlNS::table) {
                                                if (rowLocalName == "table-cell") {
                                                    // Ok, it's a cell...
                                                    const int currentRow = tbl->rows() - 1;
                                                    QTextTableCell cell = tbl->cellAt(currentRow, currentCell);
                                                    if (cell.isValid()) {
                                                        cursor = cell.firstCursorPosition();
                                                        loadBody(context, rowTag, cursor);
                                                    } else
                                                        kDebug(32500) << "Invalid table-cell row=" << currentRow << " column=" << currentCell;
                                                    currentCell++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    cursor = tbl->lastCursorPosition();
                    cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1);
                } else {
                    kWarning(32500) << "KoTextLoader::loadBody unhandled table::" << localName;
                }
#endif
            }
void ShapeSequenceReader::Initialization()
{
    isTextured = false;
    trackerInitialized = false;

    // initialize the center
    for(int i = 0; i < 3; ++i)
    {
        centerGT[i] = 0;
        centerEST[i] = 0;
    }

    SafeAllocArrayType(m_pTextureColors, 3*m_nHeight*m_nWidth, CoordinateType);
    SafeAllocArrayType(m_pCurTrackingResult, 3*m_nHeight*m_nWidth, CoordinateType);
    SafeAllocArrayType(m_pCurProjResult, 2*m_nHeight*m_nWidth, CoordinateType);
    SafeAllocArrayType(m_pCurTrackingResultNormal, 3*m_nHeight*m_nWidth, CoordinateType);

    if(m_hasGT)
    {
        SafeAllocArrayType(m_pCurTrackingResultGT, 3*m_nHeight*m_nWidth, CoordinateType);
        SafeAllocArrayType(m_pCurProjResultGT, 2*m_nHeight*m_nWidth, CoordinateType);
        SafeAllocArrayType(m_pCurTrackingResultNormalGT, 3*m_nHeight*m_nWidth, CoordinateType);
    }
    else
    {
        m_pCurTrackingResultGT = m_pCurTrackingResult;
        m_pCurProjResultGT = m_pCurProjResult;
        m_pCurTrackingResultNormalGT = m_pCurTrackingResultNormal;
    }

    // load mask
    int numPnts = m_nWidth*m_nHeight;
    if(useMask)        // column major mask
    {
        maskImage.resize(numPnts);
        std::stringstream maskImagePath;
        maskImagePath << shapePath << shapeMaskFile;

        if(bfs::exists(maskImagePath.str()))
        {
            ifstream maskFileFID(maskImagePath.str().c_str(), std::ios::binary);
            double temp;
            for(unsigned int j = 0; j < numPnts; ++j)
            {
                maskFileFID.read(reinterpret_cast<char*>(&temp),8);
                maskImage[j] = temp;
            }
            maskFileFID.close();
        }
        else
        {
            cerr << maskImagePath.str() << " does not exist! " << endl;
        }
    }
    else
    {
        maskImage.resize(numPnts);
        for(unsigned int j = 0; j < numPnts; ++j)
        {
            maskImage[j] = 1;
        }
    }
    //if mask is colMajor, convert it to row major and use it afterwards
    if(m_colMajor)
    {
        vector<double> tempMaskImage;
        tempMaskImage.resize(numPnts);
        for(int i = 0; i < m_nWidth; ++i)
        {
            for(int j = 0; j < m_nHeight; ++j)
            {
                tempMaskImage[j*m_nWidth+i] = maskImage[j+i*m_nHeight];
            }
        }
        maskImage = tempMaskImage;
    }

    loadShape(false, shapePath, shapeFormat, currentFrameNo);
    if(m_hasGT)
    {
        loadShape(true, shapePath, shapeFormatGT, currentFrameNo);
    }
    else
    {
        centerGT[0] = centerEST[0];
        centerGT[1] = centerEST[1];
        centerGT[2] = centerEST[2];
    }

    // project 3d shapes to 2d projections
    projShape();

    unsigned int radius = 1;
    computeNormal(false, radius);
    if(m_hasGT)
    computeNormal(true, radius);

}