Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:mesh_reasoning [2014/05/20 09:44] admindoc:mesh_reasoning [2014/11/28 17:03] (current) admin
Line 14: Line 14:
 Analyze a model by its direct path or a KnowRob identifier (you first have to load an OWL file with the object) Analyze a model by its direct path or a KnowRob identifier (you first have to load an OWL file with the object)
 <code> <code>
- ?- mesh_annotator_path('package://knowrob_cad_models/models/drinking_vessels/cup2.dae',Mr).+ ?- mesh_annotator_path('package://knowrob_cad_models/models/drinking-vessels/cup2.dae',Mr).
  ?- mesh_annotator(knowrob:'DrinkingBottle', Mr).  ?- mesh_annotator(knowrob:'DrinkingBottle', Mr).
 </code> </code>
Line 123: Line 123:
   * Handles (computable class for cylindrical handles, class 'Handle')   * Handles (computable class for cylindrical handles, class 'Handle')
  
 +
 +
 +
 +
 +
 +===== CAD models as source of geometric information =====
 +
 +CAD models can not only be used for visualization purposes, but can also serve as source of information about the geometry of the objects in the scene. For example, the dimensions of their bounding boxes can be read using the following commands:
 +
 +Height of the model in meters
 +<code>cad_model_zdim(identifier,Return).</code>
 +
 +Width of the model in meters
 +<code>cad_model_xdim(identifier,Return).</code>
 +
 +Depth of the model in meters
 +<code>cad_model_ydim(identifier,Return).</code>
 +
 +As a reminder, x = width, z = height, and y = depth. For a full list of query predicates check knowrob_cad_models/prolog/knowrob_cad_models.pl.
 +
 +
 +===== Writing your own CAD model parser =====
 +
 +The system comes with parsers for Collada and .ply files. You can, however, easily write your own parser for other file formats.
 +
 +===== Structure of a parser =====
 +
 +The base class for all parsers should be ''ModelParser''. It contains some essential methods for using parsers and stores a list of ''Triangles'' and ''Lines'' loaded from the model. Each parser should store the loaded data in the ''Group'' (which represents a Triangle/Lines mesh) member variable. Each group can have a name. Its ''mesh'' member variable stores the ''Triangle'' and ''Lines'' information. ''Triangles'' can have a texture and a color, ''Lines'' only a color.
 +
 +==== Model Parser ====
 +
 +The model parser is used to parse a CAD Model from a given file and is the base class for all parsers.
 +The parser loads a file and "converts" it so that it can be stored as a list of triangles and lines.
 +
 +A special feature of the ModelParser is buffering: If a model has been parsed it will be stored in a model buffer. So if the same model should be parsed again it will be taken from this buffer instead of parsing it again. Keep in mind that if you change something in a Group of a specific model it will affect all the other existing instances of this model.
 +
 +==== List of available parsers ====
 +
 +Currently the following file formats are supported:
 +  * [[#Collada Parser|Collada]]: *.dae, *.kmz
 +  * [[#PLY Parser|Polygon File Format]]: *.ply
 +
 +=== Collada Parser ===
 +The collada parser uses the [[[http://sourceforge.net/p/dae4j/|dae4j]] library to parse the Collada XML format. The current version of dae4j has not yet implemented the whole Collada specification, but still seems to the best Collada parser library for Java.
 +
 +.kmz files are compressed Collada files (zip) and will be extracted into a temporary directory and parsed from there.
 +
 +====  How to create a new parser? ==== 
 +Check out ColladaParser for a sample implementation of a parser. The necessary steps for creating a new model parser are:
 +
 +  * Create a new class and extend it from ModelParser
 +  * Add your parser to the extension list (In ModelParser.java) so a file extension will be assigned to your parser:
 +    * Example: <code>extensionAssignment.put("dae", ColladaParser.class);</code>
 +  * Implement the required methods. These should be self-explaining (see javadoc)
 +  * Store all data in the Groups member of the ModelParser parent class.