home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / legacy_mesh_modifier.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-07-03  |  4.7 KB  |  145 lines

  1. #ifndef K3DSDK_LEGACY_MESH_MODIFIER_H
  2. #define K3DSDK_LEGACY_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. #include "data.h"
  24. #include "hints.h"
  25. #include "k3d-i18n-config.h"
  26. #include "imesh_sink.h"
  27. #include "imesh_source.h"
  28. #include "ipipeline_profiler.h"
  29. #include "legacy_mesh.h"
  30. #include "mesh.h"
  31.  
  32. namespace k3d
  33. {
  34.  
  35. namespace legacy
  36. {
  37.     
  38. template<typename base_t>
  39. class mesh_modifier :
  40.     public base_t,
  41.     public imesh_sink,
  42.     public imesh_source
  43. {
  44. public:
  45.     mesh_modifier(iplugin_factory& Factory, idocument& Document) :
  46.         base_t(Factory, Document),
  47.         m_input_mesh(init_owner(*this) + init_name("input_mesh") + init_label(_("Input Mesh")) + init_description(_("Input mesh")) + init_value<k3d::mesh*>(0)),
  48.         m_output_mesh(init_owner(*this) + init_name("output_mesh") + init_label(_("Output Mesh")) + init_description(_("Output mesh")))
  49.     {
  50.         m_input_mesh.changed_signal().connect(make_reset_mesh_slot());
  51.  
  52.         m_output_mesh.set_initialize_slot(sigc::mem_fun(*this, &mesh_modifier<base_t>::initialize_mesh));
  53.         m_output_mesh.set_update_slot(sigc::mem_fun(*this, &mesh_modifier<base_t>::update_mesh));
  54.     }
  55.  
  56.     iproperty& mesh_source_output()
  57.     {
  58.         return m_output_mesh;
  59.     }
  60.  
  61.     iproperty& mesh_sink_input()
  62.     {
  63.         return m_input_mesh;
  64.     }
  65.  
  66.     sigc::slot<void, ihint*> make_reset_mesh_slot()
  67.     {
  68.         return sigc::mem_fun(*this, &mesh_modifier<base_t>::reset_mesh);
  69.     }
  70.  
  71.     sigc::slot<void, ihint*> make_update_mesh_slot()
  72.     {
  73.         return m_output_mesh.make_update_slot();
  74.     }
  75.  
  76. protected:
  77.     k3d_data(k3d::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;
  78.     k3d_data(k3d::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;
  79.  
  80. private:
  81.     void reset_mesh(ihint* const Hint)
  82.     {
  83.         m_legacy_output.reset();
  84.         m_output_mesh.reset(0, Hint);
  85.     }
  86.  
  87.     void initialize_mesh(k3d::mesh& Output)
  88.     {
  89.         if(const k3d::mesh* const input = m_input_mesh.pipeline_value())
  90.         {
  91.             m_legacy_output.reset(new legacy::mesh());
  92.  
  93.             base_t::document().pipeline_profiler().start_execution(*this, "Convert Input");
  94.             legacy::mesh legacy_input;
  95.             legacy_input = *input;
  96.             base_t::document().pipeline_profiler().finish_execution(*this, "Convert Input");
  97.  
  98.             base_t::document().pipeline_profiler().start_execution(*this, "Create Mesh");
  99.             on_initialize_mesh(legacy_input, *m_legacy_output);
  100.             base_t::document().pipeline_profiler().finish_execution(*this, "Create Mesh");
  101.  
  102.             base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  103.             on_update_mesh(legacy_input, *m_legacy_output);
  104.             base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  105.  
  106.             base_t::document().pipeline_profiler().start_execution(*this, "Convert Output");
  107.             Output = *m_legacy_output;
  108.             base_t::document().pipeline_profiler().finish_execution(*this, "Convert Output");
  109.         }
  110.     }
  111.  
  112.     void update_mesh(k3d::mesh& Output)
  113.     {
  114.         if(const k3d::mesh* const input = m_input_mesh.pipeline_value())
  115.         {
  116.             return_if_fail(m_legacy_output.get());
  117.  
  118.             base_t::document().pipeline_profiler().start_execution(*this, "Convert Input");
  119.             legacy::mesh legacy_input;
  120.             legacy_input = *input;
  121.             base_t::document().pipeline_profiler().finish_execution(*this, "Convert Input");
  122.             
  123.             base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  124.             on_update_mesh(legacy_input, *m_legacy_output);
  125.             base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  126.  
  127.             base_t::document().pipeline_profiler().start_execution(*this, "Convert Output");
  128.             Output = *m_legacy_output;
  129.             base_t::document().pipeline_profiler().finish_execution(*this, "Convert Output");
  130.         }
  131.     }
  132.  
  133.     virtual void on_initialize_mesh(const legacy::mesh& Input, legacy::mesh& Output) = 0;
  134.     virtual void on_update_mesh(const legacy::mesh& Input, legacy::mesh& Output) = 0;
  135.  
  136.     std::auto_ptr<legacy::mesh> m_legacy_output;
  137. };
  138.  
  139. } // namespace legacy
  140.  
  141. } // namespace k3d
  142.  
  143. #endif // !K3DSDK_LEGACY_MESH_MODIFIER_H
  144.  
  145.