AFLOW
 
Loading...
Searching...
No Matches
aurostd::x3DWriter Class Reference

tools to create 3D scence and export them in different More...

#include <aurostd_xparser.h>

Classes

struct  ConvexFacets
 Scene object settings for facets. More...
 
struct  Material
 Storage object for material settings. More...
 
struct  OpenCylinder
 Scene object settings for cylinders. More...
 
struct  Sphere
 Scene object settings for spheres. More...
 
struct  storage_object
 Helper to store different scene objects (utalizing shared pointers) More...
 

Public Types

enum class  animation_format { GIF , WEBM , MP4 }
 

Public Member Functions

 x3DWriter ()
 class constractor
 
 x3DWriter (const x3DWriter &x3w)
 class copy constructor
 
 ~x3DWriter ()
 default class de-constructor
 
x3DWriteroperator= (const x3DWriter &x3w)
 assignment operator
 
void clear ()
 reconstruct / clear
 
void prepareSceneLattice (const xmatrix< double > &lattice)
 prepare a scene to show a lattice by setting the center and a view collection
 
void addMaterial (const std::string &name, const xvector< double > &color)
 add a new basic Material
 
void addMaterial (const Material &newMaterial)
 add a new Material
 
std::vector< std::string > addColorSpreadMaterial (uint count)
 create a set of materials using the turbo colormap
 
template<class Container>
std::map< std::string, std::string > addNamedColorSpreadMaterial (const Container &names)
 
void addSphere (const xvector< double > &center, double radius, const std::string &material="bm_black")
 add a Sphere to the scene
 
void addSpheres (const std::vector< xvector< double > > &center, double radius, const std::string &material="bm_black")
 add a set of Sphere with a list of center and constant radius and materials
 
void addOpenCylinder (const xvector< double > &base, const xvector< double > &apex, double radius, const std::string &material="bm_grey")
 add a OpenCylinder to the scene
 
void addConvexFacets (const std::vector< xvector< double > > &vertexes, const std::vector< std::vector< uint > > &facets, const std::string &material="bm_grey_glass", const xvector< double > &shift={0, 0, 0})
 
void addConvexFacets (const std::vector< xvector< double > > &vertexes, const std::vector< std::vector< uint > > &facets, const xvector< double > &shift)
 
void addLatticeBox (const xmatrix< double > &lattice, double radius, const std::string &material="bm_black", bool axis=false)
 add a box forming a unit cell to the scene
 
void joinFacets (std::vector< xvector< double > > &vertexes, std::vector< std::vector< uint > > &facets, const std::vector< xvector< double > > &new_vertexes, const std::vector< std::vector< uint > > &new_facets) const
 combine overlapping vertexes and facets
 
void animate (float duration, const std::filesystem::path &out_folder, uint fps=30, bool lr=true)
 prepare an animation
 
std::string toHTML ()
 save scene as x3d and embed it in a html file
 
std::string toX3D (bool include_xml=true, bool replace_material=false)
 save scene as x3d (xml)
 
std::string toTachyon ()
 save scene for the tachyon renderer use tachyon to render the generated file
 

Public Attributes

xvector< double > scene_center
 center of the scene (should be set before adding objects to the scene)
 
double join_threshold = 1E-5
 threshould to join vertexes when using joinFacets
 
double tachyon_camera_theta = 0.0
 tachyon camera angle theta | rotation around 1 0 0
 
double tachyon_camera_phi = 0.0
 tachyon camera angle phi | rotation around 0 0 1
 
int tachyon_lattice_views_idx = -1
 active lattice view (-1 default tachyon viewpoint is used)
 
bool tachyon_camera_orthographic = false
 
animation_format ani_type = animation_format::GIF
 animation type (default GIF)
 
std::vector< std::pair< std::string, std::string > > meta
 meta data like title, description, reference (link back to auid)
 

Private Types

enum class  object_types { MATERIAL , SPHERE , FACET , OPEN_CYLINDER }
 

Private Member Functions

void copy (const x3DWriter &x3w)
 create a copy of x3DWriter
 
void tachyon_calculate_camera ()
 calculate the camera position (used fot tachyon)
 

Static Private Member Functions

static std::string x3d_material (const std::shared_ptr< x3DWriter::Material > &material)
 

Private Attributes

std::vector< storage_objectobjects
 storage for scene objects
 
double max_distance = 0.0
 maximum distance of scene object from the scene center (for camera position calculation)
 
double tachyon_zoom = 2.0
 zoom value for rendering the camera rendering with tachyon
 
const double tachyon_camera_angle = 45.0
 lense angle for the camera rendering with tachyon
 
xvector< double > tachyon_camera_position
 camera position for tachyon
 
std::vector< std::pair< xvector< double >, xvector< double > > > tachyon_lattice_views
 collection of camera views based on prepareSceneLattice
 
const float turbo_cmap [256][3]
 rgb values of the turbo colormap
 

Detailed Description

tools to create 3D scence and export them in different

Authors
20220922 | Hagen Eckert - created x3Dwriter
20240530 | Hagen Eckert - implemented in AFLOW4

Basic usage

// load a structure to render
const std::string structure_file = "example.vasp";
xstructure work_structure(structure_file, IOAFLOW_AUTO);
work_structure.ReScale(1.0);
// prepare x3DWriter
w.scene_center = (work_structure.lattice.getcol(1) + work_structure.lattice.getcol(2) + work_structure.lattice.getcol(3)) / 3.0;
w.addLatticeBox(work_structure.lattice, 0.1);
for (auto &a: work_structure.atoms)
w.addSphere({a.cpos[1], a.cpos[2], a.cpos[3]}, 0.3, "bm_blue");
aurostd::string2file(w.toHTML(), "/Users/nathan/Projects/AFLOW4/test_struc/AB_cP2_221_b_a.html");
#define IOAFLOW_AUTO
Definition aflow_defs.h:216
tools to create 3D scence and export them in different
void addLatticeBox(const xmatrix< double > &lattice, double radius, const std::string &material="bm_black", bool axis=false)
add a box forming a unit cell to the scene
xvector< double > scene_center
center of the scene (should be set before adding objects to the scene)
void addSphere(const xvector< double > &center, double radius, const std::string &material="bm_black")
add a Sphere to the scene
std::string toHTML()
save scene as x3d and embed it in a html file
bool string2file(const string &StringOUTPUT, const std::string &FileNameRawOUTPUT, const compression_type ct, const string &mode)
write string into a file

Definition at line 64 of file aurostd_xparser.h.

Member Enumeration Documentation

◆ object_types

enum class aurostd::x3DWriter::object_types
strongprivate
Enumerator
MATERIAL 
SPHERE 
FACET 
OPEN_CYLINDER 

Definition at line 66 of file aurostd_xparser.h.

◆ animation_format

Enumerator
GIF 
WEBM 
MP4 

Definition at line 389 of file aurostd_xparser.h.

Constructor & Destructor Documentation

◆ x3DWriter() [1/2]

aurostd::x3DWriter::x3DWriter ( )

class constractor

Definition at line 676 of file aurostd_xparser.cpp.

◆ x3DWriter() [2/2]

aurostd::x3DWriter::x3DWriter ( const x3DWriter & x3w)

class copy constructor

Definition at line 702 of file aurostd_xparser.cpp.

◆ ~x3DWriter()

aurostd::x3DWriter::~x3DWriter ( )
default

default class de-constructor

Member Function Documentation

◆ copy()

void aurostd::x3DWriter::copy ( const x3DWriter & x3w)
private

create a copy of x3DWriter

Definition at line 662 of file aurostd_xparser.cpp.

◆ tachyon_calculate_camera()

void aurostd::x3DWriter::tachyon_calculate_camera ( )
private

calculate the camera position (used fot tachyon)

Definition at line 1050 of file aurostd_xparser.cpp.

◆ x3d_material()

std::string aurostd::x3DWriter::x3d_material ( const std::shared_ptr< x3DWriter::Material > & material)
staticprivate

convert a material to x3d

Returns
x3d version of a material (xml)

Definition at line 1039 of file aurostd_xparser.cpp.

◆ operator=()

x3DWriter & aurostd::x3DWriter::operator= ( const x3DWriter & x3w)

assignment operator

Definition at line 710 of file aurostd_xparser.cpp.

◆ clear()

void aurostd::x3DWriter::clear ( )

reconstruct / clear

Definition at line 657 of file aurostd_xparser.cpp.

◆ prepareSceneLattice()

void aurostd::x3DWriter::prepareSceneLattice ( const xmatrix< double > & lattice)

prepare a scene to show a lattice by setting the center and a view collection

Definition at line 719 of file aurostd_xparser.cpp.

◆ addMaterial() [1/2]

void aurostd::x3DWriter::addMaterial ( const std::string & name,
const xvector< double > & color )

add a new basic Material

Parameters
namename to reference the Material
coloras R,G,B xvector

Definition at line 859 of file aurostd_xparser.cpp.

◆ addMaterial() [2/2]

void aurostd::x3DWriter::addMaterial ( const Material & newMaterial)

add a new Material

Parameters
newMaterial

Definition at line 868 of file aurostd_xparser.cpp.

◆ addColorSpreadMaterial()

vector< std::string > aurostd::x3DWriter::addColorSpreadMaterial ( uint count)

create a set of materials using the turbo colormap

Parameters
countnumber of materials to create

the materials will be named "auto_cs_{idx}"

Definition at line 880 of file aurostd_xparser.cpp.

◆ addNamedColorSpreadMaterial()

template<typename Container>
template std::map< std::string, std::string > aurostd::x3DWriter::addNamedColorSpreadMaterial ( const Container & names)

Definition at line 893 of file aurostd_xparser.cpp.

◆ addSphere()

void aurostd::x3DWriter::addSphere ( const xvector< double > & center,
double radius,
const std::string & material = "bm_black" )

add a Sphere to the scene

Definition at line 734 of file aurostd_xparser.cpp.

◆ addSpheres()

void aurostd::x3DWriter::addSpheres ( const std::vector< xvector< double > > & center,
double radius,
const std::string & material = "bm_black" )

add a set of Sphere with a list of center and constant radius and materials

Definition at line 747 of file aurostd_xparser.cpp.

◆ addOpenCylinder()

void aurostd::x3DWriter::addOpenCylinder ( const xvector< double > & base,
const xvector< double > & apex,
double radius,
const std::string & material = "bm_grey" )

add a OpenCylinder to the scene

Parameters
basestart point
apexend point
radiuscylinder radius
materialcylinder material

Definition at line 801 of file aurostd_xparser.cpp.

◆ addConvexFacets() [1/2]

void aurostd::x3DWriter::addConvexFacets ( const std::vector< xvector< double > > & vertexes,
const std::vector< std::vector< uint > > & facets,
const std::string & material = "bm_grey_glass",
const xvector< double > & shift = {0, 0, 0} )

◆ addConvexFacets() [2/2]

void aurostd::x3DWriter::addConvexFacets ( const std::vector< xvector< double > > & vertexes,
const std::vector< std::vector< uint > > & facets,
const xvector< double > & shift )

◆ addLatticeBox()

void aurostd::x3DWriter::addLatticeBox ( const xmatrix< double > & lattice,
double radius,
const std::string & material = "bm_black",
bool axis = false )

add a box forming a unit cell to the scene

Parameters
lattice3x3 matrix like xstructure.lattice
radiusradius of the cylinders forming the box
materialbox material

Definition at line 757 of file aurostd_xparser.cpp.

◆ joinFacets()

void aurostd::x3DWriter::joinFacets ( std::vector< xvector< double > > & vertexes,
std::vector< std::vector< uint > > & facets,
const std::vector< xvector< double > > & new_vertexes,
const std::vector< std::vector< uint > > & new_facets ) const

combine overlapping vertexes and facets

Parameters
vertexesoriginial vertexes positions
facetslist of vertex indexes forming the facets
new_vertexesupdated vertexes positions
new_facetsupdated list of vertex indexes forming the facets

Definition at line 907 of file aurostd_xparser.cpp.

◆ animate()

void aurostd::x3DWriter::animate ( float duration,
const std::filesystem::path & out_folder,
uint fps = 30,
bool lr = true )

prepare an animation

Parameters
durationanimation time in second
out_folderfolder to store the generated files
fpsframes per second
lrmove left to right

In the out_folder a render.sh script that will create a file with the stem _Animation; for rendering ffmpeg and tachyon is needed

Definition at line 993 of file aurostd_xparser.cpp.

◆ toHTML()

std::string aurostd::x3DWriter::toHTML ( )

save scene as x3d and embed it in a html file

Definition at line 1249 of file aurostd_xparser.cpp.

◆ toX3D()

std::string aurostd::x3DWriter::toX3D ( bool include_xml = true,
bool replace_material = false )

save scene as x3d (xml)

Parameters
include_xmlcreate as stand alone xml
replace_materialswitch if Materials are exported

Definition at line 1152 of file aurostd_xparser.cpp.

◆ toTachyon()

std::string aurostd::x3DWriter::toTachyon ( )

save scene for the tachyon renderer use tachyon to render the generated file

Definition at line 1065 of file aurostd_xparser.cpp.

Member Data Documentation

◆ objects

std::vector<storage_object> aurostd::x3DWriter::objects
private

storage for scene objects

Definition at line 74 of file aurostd_xparser.h.

◆ max_distance

double aurostd::x3DWriter::max_distance = 0.0
private

maximum distance of scene object from the scene center (for camera position calculation)

Definition at line 114 of file aurostd_xparser.h.

◆ tachyon_zoom

double aurostd::x3DWriter::tachyon_zoom = 2.0
private

zoom value for rendering the camera rendering with tachyon

Definition at line 115 of file aurostd_xparser.h.

◆ tachyon_camera_angle

const double aurostd::x3DWriter::tachyon_camera_angle = 45.0
private

lense angle for the camera rendering with tachyon

Definition at line 116 of file aurostd_xparser.h.

◆ tachyon_camera_position

xvector<double> aurostd::x3DWriter::tachyon_camera_position
private

camera position for tachyon

Definition at line 117 of file aurostd_xparser.h.

◆ tachyon_lattice_views

std::vector<std::pair<xvector<double>, xvector<double> > > aurostd::x3DWriter::tachyon_lattice_views
private

collection of camera views based on prepareSceneLattice

Definition at line 118 of file aurostd_xparser.h.

◆ turbo_cmap

const float aurostd::x3DWriter::turbo_cmap[256][3]
private

rgb values of the turbo colormap

Definition at line 122 of file aurostd_xparser.h.

◆ scene_center

xvector<double> aurostd::x3DWriter::scene_center

center of the scene (should be set before adding objects to the scene)

Definition at line 382 of file aurostd_xparser.h.

◆ join_threshold

double aurostd::x3DWriter::join_threshold = 1E-5

threshould to join vertexes when using joinFacets

Definition at line 383 of file aurostd_xparser.h.

◆ tachyon_camera_theta

double aurostd::x3DWriter::tachyon_camera_theta = 0.0

tachyon camera angle theta | rotation around 1 0 0

Definition at line 384 of file aurostd_xparser.h.

◆ tachyon_camera_phi

double aurostd::x3DWriter::tachyon_camera_phi = 0.0

tachyon camera angle phi | rotation around 0 0 1

Definition at line 385 of file aurostd_xparser.h.

◆ tachyon_lattice_views_idx

int aurostd::x3DWriter::tachyon_lattice_views_idx = -1

active lattice view (-1 default tachyon viewpoint is used)

Definition at line 386 of file aurostd_xparser.h.

◆ tachyon_camera_orthographic

bool aurostd::x3DWriter::tachyon_camera_orthographic = false

Definition at line 387 of file aurostd_xparser.h.

◆ ani_type

animation_format aurostd::x3DWriter::ani_type = animation_format::GIF

animation type (default GIF)

Definition at line 390 of file aurostd_xparser.h.

◆ meta

std::vector<std::pair<std::string, std::string> > aurostd::x3DWriter::meta

meta data like title, description, reference (link back to auid)

Definition at line 391 of file aurostd_xparser.h.


The documentation for this class was generated from the following files: