From: <wol...@us...> - 2009-06-10 15:49:19
|
Revision: 49 http://mevislabmodules.svn.sourceforge.net/mevislabmodules/?rev=49&view=rev Author: wolfspindler Date: 2009-06-10 15:49:15 +0000 (Wed, 10 Jun 2009) Log Message: ----------- ENH: -Some superficial clean ups applied. Modified Paths: -------------- trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.cpp trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.h Modified: trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.cpp =================================================================== --- trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.cpp 2009-06-10 12:17:57 UTC (rev 48) +++ trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.cpp 2009-06-10 15:49:15 UTC (rev 49) @@ -37,7 +37,8 @@ // Include your header. #include "mlBarcode.h" -namespace ml{ +ML_START_NAMESPACE + //----------------------------------------------------------------------------------- //! This function is not available under non-Windows-Systems. This is //! an os-independent replacement. @@ -157,7 +158,7 @@ // calling // setThreadSupport(1); // So you can potentially multiply the performance of your algorithm. - // If not called or by calling \c setThreadSupport(0) (which is the default) + // If not called or by calling setThreadSupport(0) (which is the default) // multithreading remains disabled for your algorithm. // IMPORTANT: Please activate multithreading only if you are sure that your // algorithm supports it. Otherwise subtle errors could occur. @@ -177,13 +178,16 @@ } // End ~Barcode + //-------------------------------------------------------------------------------- + //! Creates the bar coded pixel line. + //-------------------------------------------------------------------------------- void Barcode::makeCodeLine(){ int _numofchars=0, n=0; //number of chars to be coded, counter, counter int x=0, dx=0; // counter for pixels in codeline char _stripcode[9]; //code with 6 small bars (=0) and 3 large bars (=1) for one character char* _barcodefull; // text to be coded with '*' at the beginning and the end - int _color=0; //Color of the current bar + int _color=0; // Color of the current bar // One codeline is composed of: @@ -195,7 +199,7 @@ // - a light area at the end (size: _q pixels) - //set value for color + // Set value for color. _color = _background; @@ -203,27 +207,27 @@ _numofchars = strlen(_textFld->getStringValue().c_str()); - //Calculate the size of the codeline in pixel + // Calculate the size of the codeline in pixel _xsize = (int)((_numofchars+2)*(6*_x + 3*_ratio*_x) + (_numofchars+1) * _i + 2*_q); - //Check, if an old codeline exists and remove this. + // Check, if an old codeline exists and remove this. if (_codeline!=NULL) { delete [] _codeline; } - //Allocate memory for a new codeline + // Allocate memory for a new codeline _codeline = new int[_xsize]; if(!_codeline) { mlDebug("Error initializing codeline"); } - //Initialize new codeline, set all pixels to white + // Initialize new codeline, set all pixels to white for (x=0; x<_xsize; x++) { _codeline[x]=_background; } - //Allocate memory for the complete text (including 2x'*') + // Allocate memory for the complete text (including 2x'*') _barcodefull = new char [_numofchars+4]; - //Initialize new string + // Initialize new string for(int i2=0;i2<_numofchars+2;i2++) { _barcodefull[i2] =0; } @@ -234,19 +238,19 @@ strcat(_barcodefull,"*"); //'*' at the end - //Light area at the beginning + // Light area at the beginning for(x=0; x<_q; x++) { _codeline[x]=_background; } - //Now we can start to build the bars for each character + // Now we can start to build the bars for each character _color = _background; - //Loop through the complete text + // Loop through the complete text for (unsigned int i3=0; i3<strlen(_barcodefull); i3++) { - //Get the code for the i-th character + // Get the code for the i-th character strcpy(_stripcode, Code39(_barcodefull[i3])); @@ -310,8 +314,8 @@ } // end character loop - //After all this the light space at the end of the codeline should be left or - //in other words: _xsize - x == _q + // After all this the light space at the end of the codeline should be left or + // in other words: _xsize - x == _q //Light area at the end @@ -326,7 +330,7 @@ } //----------------------------------------------------------------------------- - // Returns the Code 3 of 9 value for a given ASCII character + // Returns the Code 3 of 9 value for a given ASCII character. //----------------------------------------------------------------------------- char* Barcode::Code39(char Asc) { @@ -425,6 +429,9 @@ } } + //-------------------------------------------------------------------------------- + //! Handle field changes of the field field. + //-------------------------------------------------------------------------------- void Barcode::handleNotification (Field *field) { if (!_lockNotification && field ) @@ -443,31 +450,8 @@ } //-------------------------------------------------------------------------------- - //! Sets properties of the output image with index \c outIndex - //! dependend on the properties of input image(s). - //! So for each property of the output image \c getOutImg(outIndex) - //! the corresponding properties of input image \c getInImg(0) and - //! \c getInImg(1) are merged and set. - //! - //! Access functions to the input and output images are defined - //! in the ml class \c BaseOp:\c getOutImg und BaseOp::\c getInImg. - //! Within the \c calcOutImageProps methods the properties and - //! operators are always valid and need not to be checked for validity - //! (otherwise \c calcOutImageProps wouldn't be called). - //! Access functions to the properties of an image are defined - //! in the classes \c ImageProperties, \c MedicalImageProperties and \c PagedImg: - //! -\c getImgExt, - //! -\c getBoxFromImgExt, - //! -\c getPageExt and \c setPageExt, - //! -\c getDataType and \c setDataType, - //! -\c getMinVoxelValue and -\c setMinVoxelValue, - //! -\c getMaxVoxelValue and -\c getMaxVoxelValue. - //! - //! If not implemented the default implementation copies the properties - //! of \c getInImg(0) to the output image(s). - //! - //! It is not necessary to execute the superclass implementation in this - //! method if this class is derived directly from \c BaseOp. + //! Sets properties of the output image with index outIndex + //! dependent on the properties of input image(s). //-------------------------------------------------------------------------------- void Barcode::calcOutImageProps(int /*outIndex*/) { @@ -476,9 +460,8 @@ makeCodeLine(); } + // Output image (barcode) is rotated for better use in mammogramms! - //Output image (barcode) is rotated for better use in mammogramms! - getOutImg()->setImgExt ( Vector(_xsize, _ysize, 1, 1, 1, 1)); getOutImg()->setPageExt ( Vector(_xsize, _ysize, 1, 1, 1, 1)); @@ -498,68 +481,31 @@ } //-------------------------------------------------------------------------------- - //! Implements the conversion of the untyped calcOutSubImage call into a typed one. - //!-------------------------------------------------------------------------------- - //! \c calcOutSubimage analyses the data type of the image and calls the right - //! typed (template) function to calculate the output image. - //! Usually this function is implemented in the .cpp file by using the - //! macro \c CALC_OUTSUBIMAGE2_CPP in dyadic modules or \c CALC_OUTSUBIMAGE1 in - //! monadic modules (see mlOperatorMacros.h). - //! Similar macros for other header implementations and other input/output - //! configurations are also available. - //! Please do not implement this call yourself but use macros from - //! mlOperatorsMacros.h if possible to make it easier to add new data types - //! in future releases. + //! Calls correctly typed (template) version of calcOutSubImage to calculate page + //! outSubImg of output image with index outSubImg. //-------------------------------------------------------------------------------- CALC_OUTSUBIMAGE0_CPP(Barcode); //-------------------------------------------------------------------------------- - //! In this method the algorithm must calculate the output page \c outSubImg from - //! the input subimages(s) \c inSubImg1 and \c inSubImg2. For each data type - //! this method is instanciated. Note that \c calcOutSubImage calls this - //! function by searching the correct data type and calling the correctly typed - //! template version. This is implemented automatically by the macro - //! CALC_OUTSUBIMAGE2 above. Note that this template function should - //! not be used outside this class since there could appear linker problems, - //! especially on dll-interfaces. Ask experienced template programmers before - //! doing that. Do that also before you use a debugger or performance profiler - //! on template code. - //! NOTES: - //! -\c outSubImg has the size of the page size which can be defined - //! in \c calcOutImageProps. - //! -\c inSubImg1 and \c inSubImg2 have the sizes returned by \c calcInSubImageBox. - //! There you can specify the input image regions which you need to calculate the - //! \c outSubImg. - //! -if your algorithm in \c calcOutSubImage can be executed parallely (i.e. - //! if it is thread save/reentrant) then you can use \c setThreadSupport(1) to - //! improve performance of the algorithm. Please do this only if you are very - //! sure what you are doing to avoid subtle errors :-). - //! - //! IMPORTANT: - //! Since copying image properties is time consuming \c outSubImg and - //! \c inSubImg* do not contain valid image properties. - //! Only subimage and typed subimage specific methods should be used. - //! Accessing image properties will return invalid information - //! The right way to get valid image properties is to retrieve them from - //! \c getInSubImg() or \c getOutSubImg(), respectively. + //! Method template for type-specific page calculation. Called by calcOutSubImage(). + //! \param outSubImg The typed subimage of output image outIndex loaded form file. + //! Parameter outIndex is the index of the output the subimage is calculated for and + //! is not used here. //-------------------------------------------------------------------------------- template <typename DATATYPE> void Barcode::calcOutSubImage(TSubImg<DATATYPE> *outImg, int /*outIndex*/) { - //Output image (barcode) is rotated for better use in mammogramms! + // Output image (barcode) is rotated for better use in mammogramms! Vector dim = outImg->getImgExt(); SubImgBox loc = outImg->getBox(); - DATATYPE temp_pixelvalue; + DATATYPE temp_pixelvalue=0; - if (_codeline==NULL) { makeCodeLine(); - //return; } - - // loop over whole spatial coordinates of the image + // Loop over whole spatial coordinates of the image. Vector v(0,0,0,0,0,0); for (v.x=0; v.x<dim.x; v.x++) { //v.x=x; @@ -575,4 +521,4 @@ } -} // end of namespace ml. +ML_END_NAMESPACE Modified: trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.h =================================================================== --- trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.h 2009-06-10 12:17:57 UTC (rev 48) +++ trunk/Community/General/Sources/ML/MLBarcode/mlBarcode.h 2009-06-10 15:49:15 UTC (rev 49) @@ -34,7 +34,7 @@ #ifndef __BARCODE_H #define __BARCODE_H -// Include dll-specific settings. +// Include system specific settings. #include "MLBarcodeSystem.h" // Include most ml specific things. @@ -42,159 +42,91 @@ // Be sure that all your modules are part of the ml. So collisions // with names in system files or other libraries are minimized. -namespace ml{ +ML_START_NAMESPACE //---------------------------------------------------------------------------------- - /*! This module demonstrates - - */ + //! Module to create barcode images. //---------------------------------------------------------------------------------- class MLBARCODE_EXPORT Barcode : public BaseOp{ public: - //-------------------------------------------------------------------------------- //! Constructor: - //! -Calls base class constructor to set right number of inputs and outputs - //! -Initializes fields for input and output images and algorithm parameters. - //! -Connects input and parameter fields with output field(s) to propagate - //! input changes to output(s) so that appended modules are notified on changes. - //! Note that input and output image fields are created automatically when - //! the base class constuctor is called. - //! Normal algorithm parameters must be created/initialized 'by hand' in - //! the constructor. - //! -Sets algorithm parameters like memory management (inplace calulation) or - //! multithreading support (paralallization). - //-------------------------------------------------------------------------------- Barcode(); + + //! Destructor. ~Barcode(); //-------------------------------------------------------------------------------- //@{\name Public declaration of algorithm parameters. Use fields. //-------------------------------------------------------------------------------- + //! Empty space at the beginning and the end of the code. + IntField* _qFld; + //! Width of on normal bar. + IntField* _xFld; + //! Ratio between small and large bars. + FloatField* _ratioFld; + //! Interval between two characters. + IntField* _iFld; + //! Y_Size of the image (X_Size will be calculated, depends on the number of characters). + IntField* _ysizeFld; + //! Text to be coded. + StringField* _textFld; + //! Field for barcode pixel value. + IntField* _foregroundFld; + //! Field for image background value. + IntField* _backgroundFld; - //! Empty space at the beginning and the end of the code - IntField* _qFld; - //! Width of on normal bar - IntField* _xFld; - //! Ratio between small and large bars - FloatField* _ratioFld; - //! Intervall between two characters - IntField* _iFld; - //! Y_Size of the image (X_Size will be calculated, depends on the number of characters) - IntField* _ysizeFld; - //! Text to be coded - StringField* _textFld; - //! Statusline (not used anymore) - // StringField* _statusFld; - //! Field for foreground value - IntField* _foregroundFld; - //! Field for background value - IntField* _backgroundFld; - - //! Apply new code or changes - NotifyField* _apply; /*Apply Button*/ - ToggleField* _autoApplyFld; /*AutoApply*/ + //! Field to manage the apply button. + NotifyField* _apply; + //! Field to manage the auto apply toggle. + ToggleField* _autoApplyFld; //@} private: - //! Pixelvalue for background - MLint _background; - //! Pixelvalue for foreground - MLint _foreground; - - int _lockNotification; + //! Pointer to a memory buffer for a code line. + int* _codeline; - MLint _q, _x, _i, _ysize, _xsize; - float _ratio; + //! \name Helper functions. + //@{ + //! Creates the bar coded pixel line. + virtual void makeCodeLine(); - int* _codeline; + //! Returns the Code 3 of 9 value for a given ASCII character + virtual char* Code39(char Asc); + //@} - virtual void makeCodeLine(); - virtual char* Code39(char Asc); - - //--------------------------------------------------------------------------- - //@{\name Image processing - //--------------------------------------------------------------------------- - - + //! Handle field changes of the field field. virtual void handleNotification (Field *field); - //-------------------------------------------------------------------------------- - //! Sets properties of the output image dependent on the properties - //! of input image(s). - //! So for each property of the output image \c getOutImg(outIndex) - //! the corresponding properties of input image \c getInImg(0) and - //! \c getInImg(1) are merged and set. - //! - //! Accessfunctions to the input and output images are defined - //! in the ml class \c BaseOp:\c getOutImg und \c getInImg. - //! Within the \c calcOutImageProps methods the properties and - //! operators are always valid and need not to be checked for validity - //! (otherwise \c calcOutImageProps wouldn't be called). - //! Accessfunctions to the properties of an image are defined - //! in the classes \c ImageProperties, \c MedicalImageProperties and \c PagedImg: - //! -\c getImgExt, - //! -\c getBoxFromImgExt, - //! -\c getPageExt and \c setPageExt, - //! -\c getDataType and \c setDataType, - //! -\c getMinVoxelValue and -\c setMinVoxelValue, - //! -\c getMaxVoxelValue and -\c getMaxVoxelValue. - //! - //! If not implemented the default implementation copies the properties - //! of \c getInImg(0) to the output image(s). - //-------------------------------------------------------------------------------- + //! \name Image processing. + //@{ + //! Sets properties of the output image at output outIndex. virtual void calcOutImageProps(int outIndex); - //-------------------------------------------------------------------------------- - //! This function analyses the data type of the image and calls the right - //! typed (template) function to calculate the output image. - //! Usually this function is implemented in the .cpp file by using the - //! macro \c CALC_OUTSUBIMAGE2_CPP in dyadic modules or \c CALC_OUTSUBIMAGE1 in - //! monadic modules (see mlOperatorMacros.h). - //! Similar macros for other header implementations and other input/output - //! configurations are also available. - //! Please do not implement this call yourself but use use macros from - //! mlOperatorsMacros.h if possible to make it easier to add new data types - //! in future releases. - //-------------------------------------------------------------------------------- + //! Calculates page outSubImg of output image with index outIndex by using inSubimgs. + //! \param outSubImg The subimage of output image outIndex calculated from inSubImgs. + //! \param outIndex The index of the output the subimage is calculated for. + //! \param inSubImgs Array of subimage(s) of the input(s) whose extents were specified + //! by calcInSubImageBox. Array size is given by getInputNum(). virtual void calcOutSubImage(SubImg *outSubImg, int outIndex, SubImg *inSubImgs); - //-------------------------------------------------------------------------------- - //! In this method the algorithm must calculate the output page \c outImg from - //! the input page(s) \c inImg1 and \c inImg2. For each datatype - //! this method is instanciated. Note that \c calcOutSubImage calls this - //! function by searching the correct data type and calling the correctly typed - //! template version. This is implemented automatically by the macro - //! CALC_OUTSUBIMAGE2 in the .cpp file. Note that this template function should - //! not be used outside this class since there could appear linker problems, - //! especially on dll-interfaces. Ask experienced template programmers before - //! doing that. Do that also before you use a debugger or performance profiler - //! on template code. - //-------------------------------------------------------------------------------- + //! Method template for type-specific page calculation. Called by calcOutSubImage(). + //! \param outSubImg The typed subimage of output image outIndex loaded form file. + //! Parameter outIndex is the index of the output the subimage is calculated for and + //! is not used here. template <typename DATATYPE> void calcOutSubImage(TSubImg<DATATYPE> *outImg, int /*outIndex*/); //@} - //-------------------------------------------------------------------------------- - //! This macro declares some automatically generated functions and methods - //! for the runtime system and for the initialization of this class. - //! They are needed to ask this module for its name, type and so on - //! (see mlRuntimeSubClass.h). - //! IMPORTANT: - //! -To make this class usable it is neccessary to call its - //! static \c init function declared in this macro. It must be called in the - //! dll initialization function \c mlInitDllExampleOps.h. - //! - Be sure that the class name is written correctly since the compiler - //! cannot check wrong names here. - //-------------------------------------------------------------------------------- + //! Implements interface for the runtime type system of the ML. ML_BASEOP_CLASS_HEADER(Barcode) - }; -} //end of namespace ml +ML_END_NAMESPACE + #endif //of __BARCODE_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |