43 EffectCache(): mLight(new
Light) {}
45 void clear() { effects().clear(); }
49 for(
unsigned i=0; i<effects().size(); ++i)
51 if (effects()[i]->shader()->gocMaterial()->frontDiffuse() == color)
53 return effects()[i].get();
63 effects().push_back(fx.
get());
67 const std::vector< ref<Effect> >& effects()
const {
return mEffects; }
68 std::vector< ref<Effect> >& effects() {
return mEffects; }
70 const Light* light()
const {
return mLight.get(); }
71 Light* light() {
return mLight.get(); }
74 std::vector< ref<Effect> > mEffects;
78 class AtomGeometryCache
81 AtomGeometryCache(): mDetail(1) {}
83 void clear() { mGeometryMap.clear(); }
84 const std::map< float, ref<Geometry> >& geometryMap()
const {
return mGeometryMap; }
85 std::map< float, ref<Geometry> >& geometryMap() {
return mGeometryMap; }
86 Geometry* acquireAtomGeometry(
float radius)
88 std::map< float, ref<Geometry> >::iterator it = geometryMap().find(radius);
89 if (it!=geometryMap().end())
90 return it->second.get();
94 geometryMap()[radius] = sphere;
99 int detail()
const {
return mDetail; }
100 void setDetail(
int detail) { mDetail = detail; }
103 std::map< float, ref<Geometry> > mGeometryMap;
107 class BondGeometryCache
118 BondKey(
float h,
const fvec4& c1,
const fvec4& c2,
ECapsuleCap topcap,
ECapsuleCap bottomcap): height(h), col1(c1), col2(c2), top_cap(topcap), bottom_cap(bottomcap) {}
121 return height == other.height &&
122 col1 == other.col1 &&
123 col2 == other.col2 &&
124 top_cap == other.top_cap &&
125 bottom_cap == other.bottom_cap;
127 bool operator<(
const BondKey& other)
const 129 if (top_cap!=other.top_cap)
130 return top_cap<other.top_cap;
132 if (bottom_cap!=other.bottom_cap)
133 return bottom_cap<other.bottom_cap;
135 if (height!=other.height)
136 return height<other.height;
138 if (col1!=other.col1)
139 return col1<other.col1;
141 return col2<other.col2;
145 BondGeometryCache(): mDetail(20), mDiameter(0.20f), mQuantization(100.0f) {}
147 void clear() { mGeometryMap.clear(); }
148 const std::map< BondKey, ref<Geometry> >& geometryMap()
const {
return mGeometryMap; }
149 std::map< BondKey, ref<Geometry> >& geometryMap() {
return mGeometryMap; }
152 float quant_lenght = int(length*quantization()) / quantization();
153 BondKey key(quant_lenght,c1,c2,top_cap,bottom_cap);
154 std::map< BondKey, ref<Geometry> >::iterator it = geometryMap().find( key );
155 if (it!=geometryMap().end())
158 return it->second.get();
162 ref<Geometry> cylinder =
makeCapsule( diameter()/2.0f, quant_lenght+2.0f/quantization(), detail(), top_cap, bottom_cap, c2, c1 );
164 geometryMap()[key] = cylinder;
165 return cylinder.
get();
169 int detail()
const {
return mDetail; }
170 void setDetail(
int detail) { mDetail = detail; }
172 float diameter()
const {
return mDiameter; }
173 void setDiameter(
float diameter) { mDiameter = diameter; }
175 float quantization()
const {
return mQuantization; }
176 void setQuantization(
float quantization) { mQuantization = quantization; }
179 std::map< BondKey, ref<Geometry> > mGeometryMap;
187 actorTree()->actors()->clear();
188 transformTree()->eraseAllChildren();
190 switch(moleculeStyle())
192 case MS_Wireframe: wireframeStyle(); generateRings();
break;
194 case MS_Sticks: sticksStyle(); generateRings();
break;
197 generateAtomLabels();
198 transformTree()->computeWorldMatrixRecursive();
203 if (atomLabelTemplate()->font() &&
219 text->
setMode( atomLabelTemplate()->mode() );
220 text->
setMargin( atomLabelTemplate()->margin() );
222 text->
setFont( atomLabelTemplate()->font() );
223 text->
setColor( atomLabelTemplate()->color() );
231 actorTree()->actors()->push_back(text_act.
get());
237 for(
unsigned i=0; i<atoms().size(); ++i)
240 transformTree()->addChild(tr.
get());
241 generateAtomLabel(atoms()[i].
get(), tr.
get());
248 mAtomToActorMap.clear();
249 mActorToAtomMap.clear();
250 mBondToActorMap.clear();
251 mActorToBondMap.clear();
258 std::vector<fvec3> pt;
259 std::vector<fvec4> cols;
260 for(
unsigned ibond=0; ibond<bonds().size(); ++ibond)
262 Bond* b = bond(ibond);
283 pt.push_back( center );
284 pt.push_back( center );
304 if (lineWidth() != 1.0f)
307 actorTree()->actors()->push_back(
new Actor(geom.
get(), fx.
get(),
NULL) );
312 mAtomToActorMap.clear();
313 mActorToAtomMap.clear();
314 mBondToActorMap.clear();
315 mActorToBondMap.clear();
317 EffectCache fx_cache;
318 AtomGeometryCache atom_geom_cache;
319 atom_geom_cache.setDetail(atomDetail());
320 for(
unsigned iatom=0; iatom<atoms().size(); ++iatom)
322 if (atom(iatom)->visible())
324 Effect* fx = fx_cache.acquireEffect(atom(iatom)->color());
325 float r = atom(iatom)->radius();
329 transformTree()->addChild(atom_act->
transform());
330 actorTree()->actors()->push_back( atom_act.
get() );
333 if (isActorToMoleculeMapEnabled())
336 if (isMoleculeToActorMapEnabled())
344 mAtomToActorMap.clear();
345 mActorToAtomMap.clear();
346 mBondToActorMap.clear();
347 mActorToBondMap.clear();
349 EffectCache fx_cache;
350 AtomGeometryCache atom_geom_cache;
351 atom_geom_cache.setDetail(atomDetail());
352 for(
unsigned int iatom=0; iatom<atoms().size(); ++iatom)
354 if (atom(iatom)->visible())
356 Effect* fx = fx_cache.acquireEffect(atom(iatom)->color());
357 float r = atom(iatom)->radius();
365 transformTree()->addChild(atom_act->
transform());
366 actorTree()->actors()->push_back( atom_act.
get() );
369 if (isActorToMoleculeMapEnabled())
372 if (isMoleculeToActorMapEnabled())
386 BondGeometryCache bond_geom_cache;
387 bond_geom_cache.setDetail(bondDetail());
388 for(
unsigned int ibond=0; ibond<bonds().size(); ++ibond)
390 if (bond(ibond)->visible() && bond(ibond)->atom1()->visible() && bond(ibond)->atom2()->visible())
392 Bond* b = bond(ibond);
401 float diam = b->
radius()*2.0f;
402 bond_geom_cache.setDiameter(diam);
405 transformTree()->addChild(bond_act->
transform());
410 actorTree()->actors()->push_back( bond_act.
get() );
413 if (isActorToMoleculeMapEnabled())
416 if (isMoleculeToActorMapEnabled())
424 mAtomToActorMap.clear();
425 mActorToAtomMap.clear();
426 mBondToActorMap.clear();
427 mActorToBondMap.clear();
438 BondGeometryCache bond_geom_cache;
439 bond_geom_cache.setDetail(bondDetail());
440 for(
unsigned int ibond=0; ibond<bonds().size(); ++ibond)
442 if (bond(ibond)->visible() && bond(ibond)->atom1()->visible() && bond(ibond)->atom2()->visible())
444 Bond* b = bond(ibond);
453 float diam = b->
radius()*2.0f;
454 bond_geom_cache.setDiameter(diam);
457 transformTree()->addChild(bond_act->
transform());
462 actorTree()->actors()->push_back( bond_act.
get() );
465 if (isActorToMoleculeMapEnabled())
468 if (isMoleculeToActorMapEnabled())
476 if (!cycles().empty())
483 std::vector<fvec3> pt;
484 std::vector<fvec4> cols;
485 for(
unsigned icycle=0; icycle<cycles().size(); ++icycle)
488 for(
unsigned iatom=0; iatom<cycle(icycle).size(); ++iatom)
489 aabb += (
vec3)cycle(icycle)[iatom]->coordinates();
492 for(
unsigned iatom=0; iatom<cycle(icycle).size(); ++iatom)
494 int iatom2 = (iatom+1) % cycle(icycle).size();
495 fvec3 v1 = cycle(icycle)[iatom ]->coordinates();
496 fvec3 v2 = cycle(icycle)[iatom2]->coordinates();
497 v1 += (center-v1).
normalize() * ringOffset();
498 v2 += (center-v2).
normalize() * ringOffset();
501 cols.push_back( aromaticRingColor() );
502 cols.push_back( aromaticRingColor() );
512 actorTree()->actors()->push_back(
new Actor(geom.
get(), fx.
get(),
NULL) );
Associates a Renderable object to an Effect and Transform.
const std::string & atomName() const
Vector3< float > fvec3
A 3 components vector with float precision.
LineWidth * gocLineWidth()
Transform * transform()
Returns the Transform bound tho an Actor.
void setShadowColor(const fvec4 &shadow_color)
If enabled, do depth comparisons and update the depth buffer; Note that even if the depth buffer exis...
void prepareForRendering()
Generates the geometry representing the current molecule, atom and bond settings. ...
A Renderable that renders text with a given Font.
bool showAtomName() const
Defines whether the atom name should be rendered or not. See also Molecule::setShowAtomNames().
If enabled, use the current lighting parameters to compute the vertex color; Otherwise, simply associate the current color with each vertex, see also Material, LightModel, and Light.
void setText(const String &text)
void generateAtomLabels()
If enabled, blend the incoming RGBA color values with the values in the color buffers, see also BlendFunc for more information.
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
vec3 center() const
Returns the center of the AABB.
bool useAtomColors() const
void setBorderEnabled(bool border)
void generateAtomLabel(const Atom *atom, Transform *tr)
void setColorArray(const fvec4 &color)
Fills the color array with the given color.
const fvec3 & coordinates() const
size_t size() const
Returns the number of elements of an array.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
void setMode(ETextMode mode)
void set(float linewidth)
void setDiffuse(const fvec4 &color)
void setRenderState(RenderStateNonIndexed *renderstate)
void setKerningEnabled(bool kerning)
void setBackgroundColor(const fvec4 &background_color)
void setOutlineColor(const fvec4 &outline_color)
The AABB class implements an axis-aligned bounding box using vl::real precision.
void initFrom(const std::vector< T_VectorType > &vector)
void setShadowVector(const fvec2 &shadow_vector)
If enabled, draw lines with correct filtering; Otherwise, draw aliased lines, see also LineWidth...
VLGRAPHICS_EXPORT ref< Geometry > makeCapsule(float radius, float height, int segments, ECapsuleCap top_cap, ECapsuleCap bottom_cap, const fvec4 &top_col, const fvec4 &bottom_col)
Creates a 3d capsule with rounded, flat or no caps.
void computeNormals(bool verbose=false)
Computes the normals in a "smooth" way, i.e.
LightModel * gocLightModel()
Shader * shader(int lodi=0, int pass=0)
Utility function, same as 'lod(lodi)->at(pass);'.
const fvec4 & color() const
Defines the sequence of Shader objects used to render an Actor.
static Matrix4 & getRotation(Matrix4 &out, float degrees, float x, float y, float z)
void setColor(const fvec4 &color)
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
VLGRAPHICS_EXPORT ref< Geometry > makeIcosphere(const vec3 &pos, real diameter=1, int detail=2, bool remove_doubles=true)
Creates a sphere by iteratively subdividing an icosahedron.
void setShadowEnabled(bool shadow)
void setMargin(int margin)
void setColorMaterialEnabled(bool enabled)
static Matrix4 & getTranslation(Matrix4 &out, const Vector3< float > &v)
bool operator==(const ref< T1 > &o1, const ref< T2 > &o2)
Wraps the OpenGL function glLight().
The Bond class represents a bond to be used with the Molecule class.
void setViewportAlignment(int align)
The ref<> class is used to reference-count an Object.
The Atom class represents an atom to be used with the Molecule class.
void setBorderColor(const fvec4 &border_color)
Wraps the OpenGL function glDrawArrays().
const fvec4 & color() const
void setAlignment(int align)
void setTwoSide(bool twoside)
void enable(EEnable capability)
void setBackgroundEnabled(bool background)
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
If enabled, cull polygons based on their winding in window coordinates, see also CullFace.
void setTextAlignment(ETextAlign align)
void setOutlineEnabled(bool outline)