maskhatch.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1999-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Thu Sep 23 15:49:58 1999
00010 // commit: $Id: maskhatch.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/visx/maskhatch.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED
00035 #define GROOVX_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED
00036 
00037 #include "visx/maskhatch.h"
00038 
00039 #include "geom/rect.h"
00040 
00041 #include "gfx/bbox.h"
00042 #include "gfx/canvas.h"
00043 #include "gfx/gxaligner.h"
00044 
00045 #include "io/ioproxy.h"
00046 #include "io/reader.h"
00047 #include "io/writer.h"
00048 
00049 #include "rutz/trace.h"
00050 #include "rutz/debug.h"
00051 GVX_DBG_REGISTER
00052 
00053 namespace
00054 {
00055   const io::version_id MASKHATCH_SVID = 3;
00056 }
00057 
00058 const FieldMap& MaskHatch::classFields()
00059 {
00060   static const Field MASK_FINFOS[] =
00061   {
00062     Field("numLines", &MaskHatch::itsNumLines, 5, 0, 25, 1, Field::NEW_GROUP),
00063     Field("lineWidth", &MaskHatch::itsLineWidth, 1, 0, 25, 1, Field::CHECKED)
00064   };
00065 
00066   static FieldMap MASK_FIELDS(MASK_FINFOS, &GxShapeKit::classFields());
00067 
00068   return MASK_FIELDS;
00069 }
00070 
00071 MaskHatch* MaskHatch::make()
00072 {
00073 GVX_TRACE("MaskHatch::make");
00074   return new MaskHatch;
00075 }
00076 
00077 MaskHatch::MaskHatch () :
00078   GxShapeKit(),
00079   itsNumLines(10),
00080   itsLineWidth(1)
00081 {
00082 GVX_TRACE("MaskHatch::MaskHatch");
00083 
00084   sigNodeChanged.connect(this, &MaskHatch::update);
00085 
00086   setFieldMap(MaskHatch::classFields());
00087 
00088   setAlignmentMode(GxAligner::CENTER_ON_CENTER);
00089   dbg_eval(3, getAlignmentMode());
00090 }
00091 
00092 MaskHatch::~MaskHatch() throw()
00093 {
00094 GVX_TRACE("MaskHatch::~MaskHatch");
00095 }
00096 
00097 io::version_id MaskHatch::class_version_id() const
00098 {
00099 GVX_TRACE("MaskHatch::class_version_id");
00100  return MASKHATCH_SVID;
00101 }
00102 
00103 void MaskHatch::read_from(io::reader& reader)
00104 {
00105 GVX_TRACE("MaskHatch::read_from");
00106 
00107   reader.ensure_version_id("MaskHatch", 3,
00108                            "Try cvs tag xml_conversion_20040526",
00109                            SRC_POS);
00110 
00111   readFieldsFrom(reader, classFields());
00112 
00113   reader.read_base_class("GxShapeKit", io::make_proxy<GxShapeKit>(this));
00114 }
00115 
00116 void MaskHatch::write_to(io::writer& writer) const
00117 {
00118 GVX_TRACE("MaskHatch::write_to");
00119 
00120   writer.ensure_output_version_id("MaskHatch",
00121                               MASKHATCH_SVID, 3,
00122                               "Try groovx0.8a4", SRC_POS);
00123 
00124   writeFieldsTo(writer, classFields(), MASKHATCH_SVID);
00125 
00126   writer.write_base_class("GxShapeKit", io::make_const_proxy<GxShapeKit>(this));
00127 }
00128 
00129 void MaskHatch::update()
00130 {
00131   setPercentBorder(itsLineWidth/2 + 2);
00132 }
00133 
00134 void MaskHatch::grGetBoundingBox(Gfx::Bbox& bbox) const
00135 {
00136 GVX_TRACE("MaskHatch::grGetBoundingBox");
00137 
00138   bbox.drawRect(geom::rect<double>::lbwh(0.0, 0.0, 1.0, 1.0));
00139 }
00140 
00141 void MaskHatch::grRender(Gfx::Canvas& canvas) const
00142 {
00143 GVX_TRACE("MaskHatch::grRender");
00144 
00145   if (itsNumLines == 0) return;
00146 
00147   Gfx::AttribSaver attribSaver(canvas);
00148 
00149   canvas.setLineWidth(itsLineWidth);
00150 
00151   Gfx::LinesBlock b(canvas);
00152 
00153   using geom::vec2d;
00154 
00155   for (int i = 0; i < itsNumLines; ++i)
00156     {
00157       double position = double(i)/itsNumLines;
00158 
00159       // horizontal line
00160       canvas.vertex2(vec2d(0.0, position));
00161       canvas.vertex2(vec2d(1.0, position));
00162 
00163       // vertical line
00164       canvas.vertex2(vec2d(position, 0.0));
00165       canvas.vertex2(vec2d(position, 1.0));
00166 
00167       // lines with slope = 1
00168       canvas.vertex2(vec2d(0.0, position));
00169       canvas.vertex2(vec2d(1.0-position, 1.0));
00170 
00171       canvas.vertex2(vec2d(position, 0.0));
00172       canvas.vertex2(vec2d(1.0, 1.0-position));
00173 
00174       // lines with slope = -1
00175       canvas.vertex2(vec2d(0.0, 1.0-position));
00176       canvas.vertex2(vec2d(1.0-position, 0.0));
00177 
00178       canvas.vertex2(vec2d(position, 1.0));
00179       canvas.vertex2(vec2d(1.0, position));
00180     }
00181 
00182   // final closing lines
00183   canvas.vertex2(vec2d(0.0, 1.0));
00184   canvas.vertex2(vec2d(1.0, 1.0));
00185 
00186   canvas.vertex2(vec2d(1.0, 0.0));
00187   canvas.vertex2(vec2d(1.0, 1.0));
00188 }
00189 
00190 static const char __attribute__((used)) vcid_groovx_visx_maskhatch_cc_utc20050626084015[] = "$Id: maskhatch.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00191 #endif // !GROOVX_VISX_MASKHATCH_CC_UTC20050626084015_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:42 2008 by Doxygen version 1.5.5.