Blender  V2.59
FilterNormal.cpp
Go to the documentation of this file.
00001 
00004 /* $Id: FilterNormal.cpp 35176 2011-02-25 13:39:34Z jesterking $
00005 -----------------------------------------------------------------------------
00006 This source file is part of VideoTexture library
00007 
00008 Copyright (c) 2007 The Zdeno Ash Miklas
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 
00027 #include <PyObjectPlus.h>
00028 #include <structmember.h>
00029 
00030 #include "FilterNormal.h"
00031 
00032 #include "FilterBase.h"
00033 #include "PyTypeList.h"
00034 
00035 // implementation FilterNormal
00036 
00037 // constructor
00038 FilterNormal::FilterNormal (void) : m_colIdx(0)
00039 {
00040         // set default depth
00041         setDepth(4);
00042 }
00043 
00044 // set color shift
00045 void FilterNormal::setColor (unsigned short colIdx)
00046 {
00047         // check validity of index
00048         if (colIdx < 3)
00049                 // set color shift
00050                 m_colIdx = colIdx;
00051 }
00052 
00053 // set depth
00054 void FilterNormal::setDepth (float depth)
00055 {
00056         m_depth = depth;
00057         m_depthScale = depth / depthScaleKoef;
00058 }
00059 
00060 
00061 // cast Filter pointer to FilterNormal
00062 inline FilterNormal * getFilter (PyFilter * self)
00063 { return static_cast<FilterNormal*>(self->m_filter); }
00064 
00065 
00066 // python methods and get/sets
00067 
00068 // get index of color used to calculate normal
00069 static PyObject * getColor (PyFilter * self, void * closure)
00070 {
00071         return Py_BuildValue("H", getFilter(self)->getColor());
00072 }
00073 
00074 // set index of color used to calculate normal
00075 static int setColor (PyFilter * self, PyObject * value, void * closure)
00076 {
00077         // check validity of parameter
00078         if (value == NULL || !PyLong_Check(value))
00079         {
00080                 PyErr_SetString(PyExc_TypeError, "filt.colorIdx = int: VideoTexture.FilterNormal, expected the value must be a int");
00081                 return -1;
00082         }
00083         // set color index
00084         getFilter(self)->setColor((unsigned short)(PyLong_AsSsize_t(value)));
00085         // success
00086         return 0;
00087 }
00088 
00089 
00090 // get depth
00091 static PyObject * getDepth (PyFilter * self, void * closure)
00092 {
00093         return Py_BuildValue("f", getFilter(self)->getDepth());
00094 }
00095 
00096 // set depth
00097 static int setDepth (PyFilter * self, PyObject * value, void * closure)
00098 {
00099         // check validity of parameter
00100         if (value)
00101         {
00102                 float depth= (float)PyFloat_AsDouble(value);
00103                 if ((depth==-1 && PyErr_Occurred()) == 0) /* no error converting to a float? */
00104                 {
00105                         // set depth
00106                         getFilter(self)->setDepth(depth);
00107                         // success
00108                         return 0;
00109                 }
00110         }
00111 
00112         PyErr_SetString(PyExc_TypeError, "filt.depth = float: VideoTexture.FilterNormal, expected the value must be a float");
00113         return -1;
00114 }
00115 
00116 
00117 // attributes structure
00118 static PyGetSetDef filterNormalGetSets[] =
00119 { 
00120         {(char*)"colorIdx", (getter)getColor, (setter)setColor, (char*)"index of color used to calculate normal (0 - red, 1 - green, 2 - blue)", NULL},
00121         {(char*)"depth", (getter)getDepth, (setter)setDepth, (char*)"depth of relief", NULL},
00122         // attributes from FilterBase class
00123         {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
00124         {NULL}
00125 };
00126 
00127 // define python type
00128 PyTypeObject FilterNormalType =
00129 { 
00130         PyVarObject_HEAD_INIT(NULL, 0)
00131         "VideoTexture.FilterNormal",   /*tp_name*/
00132         sizeof(PyFilter),          /*tp_basicsize*/
00133         0,                         /*tp_itemsize*/
00134         (destructor)Filter_dealloc,/*tp_dealloc*/
00135         0,                         /*tp_print*/
00136         0,                         /*tp_getattr*/
00137         0,                         /*tp_setattr*/
00138         0,                         /*tp_compare*/
00139         0,                         /*tp_repr*/
00140         0,                         /*tp_as_number*/
00141         0,                         /*tp_as_sequence*/
00142         0,                         /*tp_as_mapping*/
00143         0,                         /*tp_hash */
00144         0,                         /*tp_call*/
00145         0,                         /*tp_str*/
00146         0,                         /*tp_getattro*/
00147         0,                         /*tp_setattro*/
00148         0,                         /*tp_as_buffer*/
00149         Py_TPFLAGS_DEFAULT,        /*tp_flags*/
00150         "Filter for Blue Screen objects",       /* tp_doc */
00151         0,                             /* tp_traverse */
00152         0,                             /* tp_clear */
00153         0,                             /* tp_richcompare */
00154         0,                             /* tp_weaklistoffset */
00155         0,                             /* tp_iter */
00156         0,                             /* tp_iternext */
00157         NULL,                /* tp_methods */
00158         0,                   /* tp_members */
00159         filterNormalGetSets,           /* tp_getset */
00160         0,                         /* tp_base */
00161         0,                         /* tp_dict */
00162         0,                         /* tp_descr_get */
00163         0,                         /* tp_descr_set */
00164         0,                         /* tp_dictoffset */
00165         (initproc)Filter_init<FilterNormal>,     /* tp_init */
00166         0,                         /* tp_alloc */
00167         Filter_allocNew,           /* tp_new */
00168 };
00169