📄 dimopxt.h
字号:
/* * * Copyright (C) 1996-2005, OFFIS * * This software and supporting documentation were developed by * * Kuratorium OFFIS e.V. * Healthcare Information and Communication Systems * Escherweg 2 * D-26121 Oldenburg, Germany * * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. * * Module: dcmimgle * * Author: Joerg Riesmeier * * Purpose: DicomMonochromePixelTemplate (Header) * * Last Update: $Author: meichel $ * Update Date: $Date: 2005/12/08 16:47:56 $ * CVS/RCS Revision: $Revision: 1.27 $ * Status: $State: Exp $ * * CVS/RCS Log at end of file * */#ifndef DIMOPXT_H#define DIMOPXT_H#include "dcmtk/config/osconfig.h"#include "dcmtk/ofstd/ofconsol.h"#include "dcmtk/ofstd/ofbmanip.h"#include "dcmtk/ofstd/ofcast.h"#include "dcmtk/dcmdata/dctypes.h"#include "dcmtk/dcmdata/dcdefine.h"#include "dcmtk/dcmimgle/dimopx.h"#include "dcmtk/dcmimgle/dipxrept.h"#include "dcmtk/dcmimgle/dimomod.h"#include "dcmtk/dcmimgle/diinpx.h"#include "dcmtk/dcmimgle/dimoopx.h"/*---------------------* * class declaration * *---------------------*//** Template class to handle monochrome pixel data */template<class T>class DiMonoPixelTemplate : public DiMonoPixel, public DiPixelRepresentationTemplate<T>{ public: /** constructor * ** @param count number of pixels */ DiMonoPixelTemplate(const unsigned long count) : DiMonoPixel(count), Data(NULL) { MinValue[0] = 0; MinValue[1] = 0; MaxValue[0] = 0; MaxValue[1] = 0; // allocate buffer of given size Data = new T[Count]; } /** constructor * ** @param pixel pointer to input pixel data * @param modality pointer to object managing modality transform */ DiMonoPixelTemplate(const DiInputPixel *pixel, DiMonoModality *modality) : DiMonoPixel(pixel, modality), Data(NULL) { MinValue[0] = 0; MinValue[1] = 0; MaxValue[0] = 0; MaxValue[1] = 0; } /** constructor * ** @param pixel pointer to output pixel data used for intermediate representation * @param modality pointer to object managing modality transform */ DiMonoPixelTemplate(DiMonoOutputPixel *pixel, DiMonoModality *modality) : DiMonoPixel(pixel, modality), Data(OFstatic_cast(T *, pixel->getDataPtr())) { MinValue[0] = 0; MinValue[1] = 0; MaxValue[0] = 0; MaxValue[1] = 0; } /** destructor */ virtual ~DiMonoPixelTemplate() { delete[] Data; } /** get integer representation * ** @return integer representation of the internally stored pixel data */ inline EP_Representation getRepresentation() const { return DiPixelRepresentationTemplate<T>::getRepresentation(); } /** get pointer to internal pixel data * ** @return pointer to pixel data */ inline const void *getData() const { return OFstatic_cast(const void *, Data); } /** get pointer to internal pixel data * ** @return pointer to pixel data */ inline void *getDataPtr() { return OFstatic_cast(void *, Data); } /** get reference to pointer to internal pixel data. * The returned array points to the (single) image plane. The behaviour of * this method is, therefore, identical for both monochrome and color images. * ** @return reference to pointer to pixel data */ inline void *getDataArrayPtr() { return OFstatic_cast(void *, &Data); } /** get minimum and maximum pixel values * ** @param min reference to storage area for minimum pixel value * @param max reference to storage area for maximum pixel value * ** @return status, true if successful, false otherwise */ inline int getMinMaxValues(double &min, double &max) const { min = MinValue[0]; max = MaxValue[0]; return 1; } /** get automatically computed min-max window * ** @param idx ignore global min/max pixel values if > 0 * @param center reference to storage area for window center value * @param width reference to storage area for window width value * ** @return status, true if successful, false otherwise */ inline int getMinMaxWindow(const int idx, double ¢er, double &width) { int result = 0; if ((idx >= 0) && (idx <= 1)) { if ((idx == 1) && (MinValue[1] == 0) && (MaxValue[1] == 0)) determineMinMax(0, 0, 0x2); // determine on demand /* suppl. 33: "A Window Center of 2^n-1 and a Window Width of 2^n selects the range of input values from 0 to 2^n-1." */ center = (OFstatic_cast(double, MinValue[idx]) + OFstatic_cast(double, MaxValue[idx]) + 1) / 2; // type cast to avoid overflows ! width = OFstatic_cast(double, MaxValue[idx]) - OFstatic_cast(double, MinValue[idx]) + 1; result = (width > 0); // check for valid value } return result; } /** get automatically computed Region of Interest (ROI) window * ** @param left_pos x-coordinate of the top left-hand corner of the ROI (starting from 0) * @param top_pos y-coordinate of the top left-hand corner of the ROI (starting from 0) * @param width width in pixels of the rectangular ROI (minimum: 1) * @param height height in pixels of the rectangular ROI (minimum: 1) * @param columns number of columns (width) of the associated image * @param rows number of rows (height) of the associated image * @param frame index of the frame to be used for the calculation * @param voiCenter reference to storage area for window center value * @param voiWidth reference to storage area for window width value * ** @return status, true if successful, false otherwise */ virtual int getRoiWindow(const unsigned long left_pos, const unsigned long top_pos, const unsigned long width, const unsigned long height, const unsigned long columns, const unsigned long rows, const unsigned long frame, double &voiCenter, double &voiWidth) { int result = 0; if ((Data != NULL) && (left_pos < columns) && (top_pos < rows)) { register T *p = Data + (columns * rows * frame) + (top_pos * columns) + left_pos; const unsigned long right_pos = (left_pos + width < columns) ? left_pos + width : columns; const unsigned long bottom = (top_pos + height < rows) ? top_pos + height : rows; const unsigned long skip_x = left_pos + (columns - right_pos); register unsigned long x; register unsigned long y; register T value = 0; register T min = *p; // get first pixel as initial value for min ... register T max = min; // ... and max for (y = top_pos; y < bottom; ++y) { for (x = left_pos; x < right_pos; ++x) { value = *(p++); if (value < min) min = value; else if (value > max) max = value; } p += skip_x; // skip rest of current line and beginning of next } /* suppl. 33: "A Window Center of 2^n-1 and a Window Width of 2^n selects the range of input values from 0 to 2^n-1." */ voiCenter = (OFstatic_cast(double, min) + OFstatic_cast(double, max) + 1) / 2; // type cast to avoid overflows ! voiWidth = OFstatic_cast(double, max) - OFstatic_cast(double, min) + 1; result = (width > 0); // check for valid value } return result; } /** get automatically computed histogram window * ** @param thresh ignore certain percentage of pixels at lower and upper boundaries * @param center reference to storage area for window center value * @param width reference to storage area for window width value * ** @return status, true if successful, false otherwise */ int getHistogramWindow(const double thresh, // could be optimized if necessary (see diinpxt.h)! double ¢er, double &width) { if ((Data != NULL) && (MinValue[0] < MaxValue[0])) { const Uint32 count = OFstatic_cast(Uint32, MaxValue[0] - MinValue[0] + 1); Uint32 *quant = new Uint32[count]; if (quant != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -