home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / mesh_modifier.h < prev    next >
C/C++ Source or Header  |  2008-12-09  |  4KB  |  114 lines

  1. #ifndef K3DSDK_MESH_MODIFIER_H
  2. #define K3DSDK_MESH_MODIFIER_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2006, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.         \author Timothy M. Shead (tshead@k-3d.com)
  25.         \author Romain Behar (romainbehar@yahoo.com)
  26. */
  27.  
  28. #include "data.h"
  29. #include "k3d-i18n-config.h"
  30. #include "idocument.h"
  31. #include "imesh_sink.h"
  32. #include "imesh_source.h"
  33. #include "ipipeline_profiler.h"
  34. #include "mesh.h"
  35.  
  36. namespace k3d
  37. {
  38.  
  39. template<typename base_t>
  40. class mesh_modifier :
  41.     public base_t,
  42.     public imesh_sink,
  43.     public imesh_source
  44. {
  45. public:
  46.     mesh_modifier(iplugin_factory& Factory, idocument& Document) :
  47.         base_t(Factory, Document),
  48.         m_input_mesh(init_owner(*this) + init_name("input_mesh") + init_label(_("Input Mesh")) + init_description(_("Input mesh")) + init_value<mesh*>(0)),
  49.         m_output_mesh(init_owner(*this) + init_name("output_mesh") + init_label(_("Output Mesh")) + init_description(_("Output mesh")))
  50.     {
  51.         m_input_mesh.changed_signal().connect(make_reset_mesh_slot());
  52.  
  53.         m_output_mesh.set_initialize_slot(sigc::mem_fun(*this, &mesh_modifier<base_t>::initialize_mesh));
  54.         m_output_mesh.set_update_slot(sigc::mem_fun(*this, &mesh_modifier<base_t>::update_mesh));
  55.     }
  56.  
  57.     iproperty& mesh_source_output()
  58.     {
  59.         return m_output_mesh;
  60.     }
  61.  
  62.     iproperty& mesh_sink_input()
  63.     {
  64.         return m_input_mesh;
  65.     }
  66.  
  67.     sigc::slot<void, ihint*> make_reset_mesh_slot()
  68.     {
  69.         return m_output_mesh.make_reset_slot();
  70.     }
  71.  
  72.     sigc::slot<void, ihint*> make_update_mesh_slot()
  73.     {
  74.         return m_output_mesh.make_update_slot();
  75.     }
  76.  
  77. protected:
  78.     k3d_data(mesh*, data::immutable_name, data::change_signal, data::no_undo, data::local_storage, data::no_constraint, data::read_only_property, data::no_serialization) m_input_mesh;
  79.     k3d_data(mesh*, data::immutable_name, data::change_signal, data::no_undo, data::pointer_storage, data::no_constraint, data::read_only_property, data::no_serialization) m_output_mesh;
  80.  
  81. private:
  82.     void initialize_mesh(mesh& Output)
  83.     {
  84.         if(const mesh* const input = m_input_mesh.pipeline_value())
  85.         {
  86.             base_t::document().pipeline_profiler().start_execution(*this, "Create Mesh");
  87.             on_create_mesh(*input, Output);
  88.             base_t::document().pipeline_profiler().finish_execution(*this, "Create Mesh");
  89.  
  90.             base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  91.             on_update_mesh(*input, Output);
  92.             base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  93.         }
  94.     }
  95.  
  96.     void update_mesh(mesh& Output)
  97.     {
  98.         if(const mesh* const input = m_input_mesh.pipeline_value())
  99.         {
  100.             base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  101.             on_update_mesh(*input, Output);
  102.             base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  103.         }
  104.     }
  105.  
  106.     virtual void on_create_mesh(const mesh& Input, mesh& Output) = 0;
  107.     virtual void on_update_mesh(const mesh& Input, mesh& Output) = 0;
  108. };
  109.  
  110. } // namespace k3d
  111.  
  112. #endif // !K3DSDK_MESH_MODIFIER_H
  113.  
  114.