APixmap.hh 4.54 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Will Schroeder's avatar
Will Schroeder committed
4
5
6
7
8
  Module:    APixmap.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Ken Martin's avatar
Ken Martin committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

Copyright (c) 1993-1995 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Will Schroeder's avatar
Will Schroeder committed
38
39
40
41
42
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.


=========================================================================*/
Ken Martin's avatar
Ken Martin committed
43
// .NAME vtkAPixmap - scalar data in rgba (color + transparency) form
Will Schroeder's avatar
Will Schroeder committed
44
// .SECTION Description
Ken Martin's avatar
Ken Martin committed
45
// vtkAPixmap is a concrete implementation of vtkScalars. Scalars are
Will Schroeder's avatar
Will Schroeder committed
46
47
48
49
// represented using three values for color (red, green, blue) plus alpha
// transparency value. Each of r,g,b,a components ranges from (0,255) (i.e.,
// an unsigned char value).

Ken Martin's avatar
Ken Martin committed
50
51
#ifndef __vtkAPixmap_h
#define __vtkAPixmap_h
Will Schroeder's avatar
Will Schroeder committed
52
53

#include "CoScalar.hh"
54
#include "UCArray.hh"
Will Schroeder's avatar
Will Schroeder committed
55

Ken Martin's avatar
Ken Martin committed
56
class vtkAPixmap : public vtkColorScalars 
Will Schroeder's avatar
Will Schroeder committed
57
58
{
public:
Ken Martin's avatar
Ken Martin committed
59
60
61
62
  vtkAPixmap() {};
  ~vtkAPixmap() {};
  vtkAPixmap(const vtkAPixmap& fs) {this->S = fs.S;};
  vtkAPixmap(const int sz, const int ext=1000):S(4*sz,4*ext){};
Will Schroeder's avatar
Will Schroeder committed
63
64
  int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(4*sz,4*ext);};
  void Initialize() {this->S.Initialize();};
Ken Martin's avatar
Ken Martin committed
65
  char *GetClassName() {return "vtkAPixmap";};
Will Schroeder's avatar
Will Schroeder committed
66

Ken Martin's avatar
Ken Martin committed
67
68
  // vtkScalar interface
  vtkScalars *MakeObject(int sze, int ext=1000);
Will Schroeder's avatar
Will Schroeder committed
69
70
  int GetNumberOfScalars() {return (this->S.GetMaxId()+1)/4;};
  void Squeeze() {this->S.Squeeze();};
71
  int GetNumberOfValuesPerScalar() {return 4;};
Will Schroeder's avatar
Will Schroeder committed
72
73

  // miscellaneous
Ken Martin's avatar
Ken Martin committed
74
75
  vtkAPixmap &operator=(const vtkAPixmap& fs);
  void operator+=(const vtkAPixmap& fs) {this->S += fs.S;};
Will Schroeder's avatar
Will Schroeder committed
76
  void Reset() {this->S.Reset();};
77
78
  unsigned char *GetPtr(const int id);
  unsigned char *WritePtr(const int id, const int number);
79
  void WrotePtr();
Will Schroeder's avatar
Will Schroeder committed
80

Ken Martin's avatar
Ken Martin committed
81
  // vtkColorScalar interface.
Will Schroeder's avatar
Will Schroeder committed
82
83
84
85
86
87
88
  unsigned char *GetColor(int id);
  void GetColor(int id, unsigned char rgba[4]);
  void SetColor(int id, unsigned char rgba[4]);
  void InsertColor(int id, unsigned char rgba[4]);
  int InsertNextColor(unsigned char rgba[4]);

protected:
89
  vtkUnsignedCharArray S;
Will Schroeder's avatar
Will Schroeder committed
90
91
};

Will Schroeder's avatar
Will Schroeder committed
92
93
// Description:
// Return a rgba color at array location i.
Ken Martin's avatar
Ken Martin committed
94
inline unsigned char *vtkAPixmap::GetColor(int i) 
Will Schroeder's avatar
Will Schroeder committed
95
96
97
98
{
  return this->S.GetPtr(4*i);
}

99
// Description:
100
// Get pointer to array of data starting at data position "id".
Ken Martin's avatar
Ken Martin committed
101
inline unsigned char *vtkAPixmap::GetPtr(const int id)
102
103
104
105
106
{
  return this->S.GetPtr(4*id);
}

// Description:
107
108
109
110
// Get pointer to data array. Useful for direct writes of data. MaxId is 
// bumped by number (and memory allocated if necessary). Id is the 
// location you wish to write into; number is the number of scalars to 
// write. Use the method WrotePtr() to mark completion of write.
Ken Martin's avatar
Ken Martin committed
111
inline unsigned char *vtkAPixmap::WritePtr(const int id, const int number)
112
113
114
115
{
  return this->S.WritePtr(4*id,4*number);
}

116
117
118
// Description:
// Terminate direct write of data. Although dummy routine now, reserved for
// future use.
Ken Martin's avatar
Ken Martin committed
119
inline void vtkAPixmap::WrotePtr() {}
120

Will Schroeder's avatar
Will Schroeder committed
121
#endif