Code Search for Developers
 
 
  

internals_patterns.html from PovClipse at Krugle


Show internals_patterns.html syntax highlighted

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>5.4. Patterns</title><link rel="stylesheet" href="megapov.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="MegaPOV Documentation"><link rel="up" href="internals.html" title="Chapter 5. Internals"><link rel="previous" href="parser.html" title="5.3. Parser"><link rel="next" href="internals_expressions.html" title="5.5. Expressions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.4. Patterns</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="parser.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Internals</th><td width="20%" align="right"> <a accesskey="n" href="internals_expressions.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="internals_patterns"></a>5.4. Patterns</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="internals_mem_patterns"></a>5.4.1. Reducing memory usage</h3></div><div><div class="author"><h3 class="author"><span class="firstname">Yvo</span> <span class="surname">Smellenbergh</span></h3></div></div></div><div></div></div><p>
    MegaPOV introduces a new patch named 'LESS_MEMORY_IN_PATTERNS_PATCH' to
    reduce the amount of memory needed for each pattern.
    This is done by replacing the structs in the union <i class="parameter"><tt>Vals</tt></i> by pointers.
    The original size of <i class="parameter"><tt>Vals</tt></i> was about 104 bytes, occupied by the crackle pattern.
  </p><p>
    By using pointers, the size is reduced to 4 bytes plus the size of the data required
    for a specific pattern.
    If for example Function pattern is used, the size of <i class="parameter"><tt>Vals</tt></i> is 4 plus the size for the 
    2 pointers which is 8.
    This total of 12 is a whole lot less than the original 104!
    This patch will increase the amount of memory used if only crackle is used. However, 
    this is unlikely to happen.
  </p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="adding_patterns"></a>5.4.1.1. Adding new patterns</h4></div></div><div></div></div><p>
    Because MegaPOV is designed to turn on and off each patch separately, you must be 
    careful whenever a patch is added.
    This patch changes many parts of the code and especially the definition of 
    <i class="parameter"><tt>TPATTERN_FIELDS</tt></i> is a bit tricky.
    For example, the ANGLE_OF_INCIDENCE_PATCH is added to the <i class="parameter"><tt>TPATTERN_FIELDS
    </tt></i> definition like this in <tt class="filename">frame.h</tt>.
    First you define it like this:
      
</p><pre class="programlisting">#ifdef ANGLE_OF_INCIDENCE_PATCH
  #ifdef LESS_MEMORY_IN_PATTERNS_PATCH
    typedef struct  {  VECTOR AOI_origin;  unsigned char pt_fixed;
    }AOI, *AOIPTR ;
    #define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i>  AOIPTR Aoi;
  #else
   #define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> struct { VECTOR AOI_origin; unsigned char pt_fixed; } Aoi;
  #endif
#else //ANGLE_OF_INCIDENCE_PATCH
  #define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i>
 #endif</pre><p>
    and then add it to the <i class="parameter"><tt>TPATTERN_FIELDS</tt></i> definition like this:
 </p><pre class="programlisting">#define <i class="parameter"><tt>TPATTERN_FIELDS</tt></i>       \
 unsigned short Type, Wave_Type, Flags; \
 :            \
 union {                     \
   DENSITY_FILE *Density_File; \
   : \
   <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> \
   : \
   ProjectionDef \
 } Vals;</pre><p> 
    <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> is always defined to avoid two definitions
    for <i class="parameter"><tt>TPATTERN_FIELDS</tt></i>.
    If ANGLE_OF_INCIDENCE_PATCH isn't defined, <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> 
    is empty and is ignored, if ANGLE_OF_INCIDENCE_PATCH is defined, <i class="parameter"><tt>AngleOfIncidenceDef
    </tt></i> is a pointer or a struct, depending on whether LESS_MEMORY_IN_PATTERNS_PATCH is 
    defined or not.
  </p><p>
    This leaves us with the problem of accessing the members of the members of <i class="parameter"><tt>Vals</tt></i>.
    In <tt class="filename">frame.h</tt> LESS_MEMORY_PATCH_MO is defined like this:
</p><pre class="programlisting">#ifdef LESS_MEMORY_IN_PATTERNS_PATCH
  #define LESS_MEMORY_PATCH_MO -&gt;
#else
  #define LESS_MEMORY_PATCH_MO .
#endif</pre><p>
    Whenever you access a member from an element of <i class="parameter"><tt>Vals</tt></i> you use
</p><pre class="programlisting">New-&gt;Vals.Crackle LESS_MEMORY_PATCH_MO lastseed = 0x8000000;</pre><p>
    which results in 
</p><pre class="programlisting">New-&gt;Vals.Crackle.lastseed = 0x8000000;
or
New-&gt;Vals.Crackle-&gt;lastseed = 0x8000000;</pre><p>
    depending on the state of the switch LESS_MEMORY_IN_PATTERNS_PATCH.
  </p><p>
    For each pattern added, which uses a pointer, memory is allocated in the following functions:
    </p><div class="itemizedlist"><ul type="disc" compact><li><tt class="filename">parstxtr.cpp</tt> - Parse_Pattern();</li><li><tt class="filename">pattern.cpp</tt> - Copy_TPat_Fields();</li></ul></div><p>
    Memory is freed for each new pattern in:
    </p><div class="itemizedlist"><ul type="disc" compact><li><tt class="filename">pattern.cpp</tt> - Destroy_TPat_Fields();</li></ul></div><p>
    The best way to find all necessary changes is to find all occurrences of one patch and take a look on how
    it is implemented.
    </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="parser.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="internals.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="internals_expressions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.3. Parser </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.5. Expressions</td></tr></table></div></body></html>




See more files for this project here

PovClipse

PovClipse is an eclipse editor plugin for Povray (Persistence of Vision Raytracer) sceene- and include files.\r\nIt features syntax highlighting, code folding, code assist, outline view as well as running Povray using render configurations.

Project homepage: http://sourceforge.net/projects/povclipse
Programming language(s): Java
License: other

  icons/
    blank.png
    caution.gif
    caution.png
    caution.tif
    draft.png
    home.gif
    home.png
    important.gif
    important.png
    important.tif
    next.gif
    next.png
    note.gif
    note.png
    note.tif
    prev.gif
    prev.png
    tip.gif
    tip.png
    tip.tif
    toc-blank.png
    toc-minus.png
    toc-plus.png
    up.gif
    up.png
    warning.gif
    warning.png
    warning.tif
  img/
    coll_con.png
    coll_face.png
    coll_mass.png
    con_visc.png
    con_vk.png
    connections1.png
    env_force.png
    env_impact.png
    expo1.png
    expo2.png
    faces1.png
    formula001.png
    formula001_print.png
    formula002.png
    formula002_print.png
    formula003.png
    formula003_print.png
    formula004.png
    formula004_print.png
    formula005.png
    formula005_print.png
    formula006.png
    formula006_print.png
    hdr1.png
    hdr2.png
    hdr3.png
    macro01.png
    macro02.png
    macro03a.png
    macro03b.png
    macro03c.png
    macro03d.png
    macro03e.png
    macro03f.png
    macro04.png
    macro05a.png
    macro05b.png
    macro05c.png
    macro05d.png
    macro05e.png
    macro06.png
    macro07.png
    macro09.png
    macro10a.png
    macro10b.png
    macro10c.png
    macro10d.png
    macro10e.png
    macro11.png
    macro12.png
    masses1.png
    patch01.png
    rad_halton_1600a.png
    rad_halton_1600b.png
    rad_halton_300a.png
    rad_halton_300b.png
    rad_halton_50a.png
    rad_halton_50b.png
    rad_internal_1600a.png
    rad_internal_1600b.png
    rad_internal_300a.png
    rad_internal_300b.png
    rad_internal_50a.png
    rad_internal_50b.png
    rad_sampling.png
    rad_viz_low_count.png
    rad_viz_sampling.png
    titlepage.png
    tut_drape01.jpg
    tut_drape02.jpg
    tut_drape03.jpg
    tut_drape04.jpg
    tut_drape05.jpg
    tut_hdr_1.png
    tut_hdr_2.png
    tut_hdr_3.png
    tut_hdr_env1.png
    tut_hdr_env2.png
    tut_hdr_res1.png
    tut_hdr_res2.png
    tut_hdr_view.hdr
    tut_hdr_view1.png
    tut_hdr_view2.png
    tut_nappe01.jpg
    tut_nappe02.jpg
    tut_nappe03.jpg
    tut_nappe04.jpg
    tutorial01.png
    tutorial02.png
    tutorial03.png
    tutorial04.png
    tutorial05.png
    tutorial06.png
    tutorial07.png
    tutorial08.png
    tutorial09.png
  msim_tut/
    tutorial01.pov
    tutorial02.mpg
    tutorial02.pov
    tutorial03.mpg
    tutorial03.pov
    tutorial04.mpg
    tutorial04.pov
    tutorial05.mpg
    tutorial05.pov
    tutorial06.mpg
    tutorial06.pov
    tutorial07.mpg
    tutorial07.pov
    tutorial08.mpg
    tutorial08.pov
    tutorial09.mpg
    tutorial09.pov
  appendices.html
  binaries.html
  camera.html
  contribution.html
  effects.html
  enable.html
  expressions.html
  global_settings.html
  inc_pprocess.inc.html
  include.html
  index.html
  internals.html
  internals_expressions.html
  internals_patterns.html
  introduction.html
  mechsim.inc.html
  megapov.css
  megapov0121.html
  megapov_index.html
  mp_consts.inc.html
  mp_types.inc.html
  multiformat_documentation.html
  nappe.pov
  news.html
  objects.html
  old_megapov.html
  parser.html
  patterns.html
  references.html
  tone_mapping.inc.html
  tutorials.html
  tutorials_hdri.html
  tutorials_simulation.html
  where.html
  why.html