something wrong with convert a stl file to a jpg/png file.

OS: Ubuntu 16.04.2 LTS
OCC: occ 7.0

I write a program to get a jpg/png file from a stl file, compile and run, and it seems everything is OK, But the jpg/png I get can't open by the window 7 's picture view Tool.

My source code is here:

#include <iostream>
#include "TopoDS.hxx"
#include "StlAPI_Reader.hxx"
#include "Standard_Handle.hxx"
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <gp_XYZ.hxx>

#include <StlTransfer.hxx>
#include <StlMesh_Mesh.hxx>
#include <BRepBndLib.hxx>
#include <Bnd_Box.hxx>

#include <Aspect_DisplayConnection.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <Xw_Window.hxx>
#include <Aspect_Window.hxx>
#include <IGESToBRep_Reader.hxx>
#include <StlAPI_Writer.hxx>

#include <Graphic3d_GraphicDriver.hxx>
#include <BRepPrimAPI_MakeWedge.hxx>

void myJpg2(TopoDS_Shape shape){
    // create a dummy display  connection 
    Handle(Aspect_DisplayConnection)  aDisplayConnection = new Aspect_DisplayConnection(); 
    // create a graphic driver 
    Handle  (Graphic3d_GraphicDriver) aDriver = new OpenGl_GraphicDriver(aDisplayConnection);     
    Handle  (Xw_Window) aWindow =  new Xw_Window (aDisplayConnection,  "My", 0,0,800,600);  
    // set up the window as  virtual 
    aWindow->SetVirtual  (Standard_True);  
    // create a view and an  interactive context 
    Handle  (V3d_Viewer) aViewer =  new V3d_Viewer (aDriver,                                
        Standard_ExtString ("Virtual"));  
    Handle  (AIS_InteractiveContext) aContext = new AIS_InteractiveContext (aViewer);  
    Handle  (V3d_View) aView = aViewer->CreateView ();  
    // assign the virtual window  to the view 
    aView->SetWindow  (aWindow);  
    // display a 3D scene 
    Handle (AIS_Shape) aBox = new AIS_Shape (shape);  
    aContext->Display  (aBox);  aView->FitAll();  
    // dump the 3D scene into an  image file 
    aView->Dump  ("3dscene.png");

int main(){
    TopoDS_Shape shape;
    StlAPI_Reader reader;
    Standard_CString aFileName;
    aFileName = "/root/sxs.stl";



The guide offered by the official has a demo about dump a png file in Os windows, but no demo in Os linux. 

I search google but i got nothing, if any one can help,  tks very very much.

Kirill Gavrilov's picture

This is an image in PPM format - OCCT generates image in this format if it has been built without FreeImage support
(see OCCT building instructions how to enable optional FreeImage library).

haizhao li's picture

Your are right,  tks !!!   And I found the source code bellow.

bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
  if (myLibImage == NULL)
    return false;
  ...................... There is a lot of code ...........
  const Standard_Integer aLen = theFileName.Length();
  if ((aLen >= 4) && (theFileName.Value (aLen - 3) == '.')
      && strcasecmp( theFileName.ToCString() + aLen - 3, "ppm") == 0 )
    return savePPM (theFileName);
  std::cerr << "Image_PixMap, no image library available! Image saved in PPM format.\n";
  return savePPM (theFileName);