<< Chapter < Page
  Digital signal processing - dsp     Page 16 / 24
Chapter >> Page >

Listing 12 also signals the end of the constructor for the class named ImgMod29 .

Six different inner classes

We have finally gotten to the fun part of the program. This is the part where we write the code that determines how the surface elevations and the calibrationscale values are displayed. This part of the program consists of six different inner classes.

The fact that the classes are inner classes makes it possible for methods in the class to access instance variables and methods of the containing object oftype ImgMod29 . This makes the programming somewhat easier than would be the case if they were all top-level classes.

Subclasses of the canvas class

Each of the six inner classes is a subclass of the class named Canvas and each of the classes overrides the paint method. The code in the overridden paint methods for the classes that display the 3D surfaces

  • access the surface elevation data,
  • convert that data into colors and,
  • display those colors in the correct locations on the screen.

The names and behaviors of three of those three classes are:

  • CanvasType0surface - Displays a Grayscale plot
  • CanvasType1surface - Displays a Color Shift plot
  • CanvasType2surface - Displays a Color Contour plot

Associated directly with the three above classes are three other inner classes that are used to display the calibration scale immediately below theplot of the 3D surface. The names and behaviors of those three classes are:

  • CanvasType0scale - Displays a Grayscale calibration scale
  • CanvasType1scale - Displays a Color Shift calibration scale
  • CanvasType2scale - Displays a Color Contour calibration scale

The getCenter method

Before getting into the details of these inner classes, however, I will present and briefly discuss a method named getCenter , which is called by the constructor for each of the surface plotting classes.

The getCenter method is used to find the horizontal and vertical center of the surface. These values are used to position the optionalred axes that may be drawn on the surface. This method is shown in its entirety in Listing 13 .

Listing 13. The method named getCenter.
int horizCenter; int vertCenter;void getCenter(){ if(dataWidth%2 == 0){//evenhorizCenter = dataWidth * blockSize/2 + blockSize/2;}else{//odd horizCenter = dataWidth * blockSize/2;}//end elseif(dataHeight%2 == 0){//even vertCenter =dataHeight * blockSize/2 + blockSize/2; }else{//oddvertCenter = dataHeight * blockSize/2; }//end else}//end getCenter

Even or odd is very important

Note that the returned values depend on whether the dimensions of the surface are even or odd.

(For example, the center of a string of five blocks of pixels is the third block whereas the center of a string of six blocks of pixels is halfway between the third and fourth blocks.)

Now that you know about the difference between even and odd surface dimensions, the code in Listing 13 should be straightforward and should not require further discussion.

Grayscale plot format

Listing 14 shows the beginning of the class named CanvasType0surface and also shows the entire constructor for that class.

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing - dsp. OpenStax CNX. Jan 06, 2016 Download for free at https://legacy.cnx.org/content/col11642/1.38
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?

Ask