Palette Data

Palette Data

Hi John,

In your example SIN2D for VB you indicated that one may alternatively use palettes instead of RGBA. I am trying to do just that, but I cannot find a method in Avlib that is analogues to the method CopyPaletteData of CVF Avis2d.ocx.

Thanks very much for your help.

Yitzak.

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I found out how to copy Palettes.However, I do not get the effectof colors vertically(from top to bottom) like CVF, but rather horizontally (from left to right).

Please help

Thanks , Yitzak

I'm not quite sure what you mean. Could you post the code?

Thanks

John

below is my modifyed SINE2D codethat include both CVF AVIS2D and IVF avGrapgCtl. Also, I added Avis2d to the FORM1

Thanks Yizak

Const numRows = 200
Const numCols = 200
Const fPi = 3.14159265358979
Dim m_root As IAvGroup
Dim m_data As IAvDataset
' ***Addition*** : Pdata is the palettes data set
Dim m_Pdata As IAvDataset
Dim m_fAmp As Single
Dim m_fDropoff As Single
Dim m_fFreq As Single
Dim m_fvData() As Single
Dim m_PvData() As Long

Private Sub Form_Load()
ReDim m_fvData(numRows - 1, numCols - 1)
m_fAmp = 1#
m_fDropoff = 0.4
m_fFreq = 3#
Set m_root = New AvGroup
m_root.Name = "root"
Set m_data = m_root.Datasets.CreateDataset("data")
' ***Addition*** : Palettes data set creation
Set m_Pdata = m_root.Datasets.CreateDataset("Pdata")
Dim graph As IAvGraph3D
Dim light As Single
Set graph = m_root.Graphs.CreateGraph3D("graph")
'The default Origin and Size is -1 and 2 in X, Y, and Z
'Shortening the height of the box a bit will look better for
' most height plot graphs
graph.Transform.Origin(AV_ZCOORD) = -0.6
graph.Transform.Size(AV_ZCOORD) = 1.2
Avis2D1.ZScale = 0.5
'Draw a green rectangular box around the box
graph.Border.Color = m_root.Context.RGBA(0, 255, 0, 255)
graph.Border.Visible = True
' Move the camera in a bit
graph.Camera.Viewpoint(AV_XCOORD) = 2#
graph.Camera.Viewpoint(AV_YCOORD) = 2#
graph.Camera.Viewpoint(AV_ZCOORD) = 3

' ***Addition set the same viewpoint for AVis2d
Avis2D1.CamXPos = 2#
Avis2D1.CamYPos = 2#
Avis2D1.CamZPos = 3#

' Create a height plot
Dim hplot As IAvHeightPlot
Set hplot = graph.Plots.CreatePlot("hplot", AV_HEIGHTPLOT)
' Tell the height plot to get its data from the dataset we created using m_fvData
hplot.XYSource = "/data"
' ***Addition*** : Tell the height plot to get its Palette data from the dataset we created
' using m_PvData
hplot.Color.ColorSource = "/Pdata"
hplot.Color.ColorSourceFormat = AV_RGBA
'Set the surface color to red.
' Alternatively, we could set up a palette and map points on the plot to different
' colors based on the height.

ReDim m_PvData(255) As Long
For i = 0 To 255
m_PvData(i) = m_root.Context.RGBA(255, 255 - i, 0, 255)
Next i
' ***Addition*** copy Palettes to both IFV and CVF
m_Pdata.WriteData (m_PvData)
Avis2D1.CopyPaletteData (m_PvData)

'Set the position to be just inside the parent graph region
hplot.Position.Origin(AV_XCOORD) = -1#
hplot.Position.Origin(AV_YCOORD) = -1#
hplot.Position.Origin(AV_ZCOORD) = -0.5
hplot.Position.Size(AV_XCOORD) = 2#
hplot.Position.Size(AV_YCOORD) = 2#
hplot.Position.Size(AV_ZCOORD) = 1#
'Set the transform to cover the index values of the array in the
'X and Y directions. And to the range [-1.0, 1.0] in the Z (since we
' know m_fvData values won't fall outside that range).
hplot.Transform.Origin(AV_XCOORD) = 0#
hplot.Transform.Origin(AV_YCOORD) = 0#
hplot.Transform.Origin(AV_ZCOORD) = -1#
hplot.Transform.Size(AV_XCOORD) = numRows
hplot.Transform.Size(AV_YCOORD) = numCols
hplot.Transform.Size(AV_ZCOORD) = 2#
'Adjust the number of grid lines proportionally with the array size
hplot.Grid.ColSpacing
= 5
hplot.Grid.RowSpacing = 5
hplot.Grid.Visible = True
'Set up form
Text1.Text = m_fDropoff
HScroll1.Value = m_fDropoff * 100#

'Update data array, Dataset

Call Recalc
'Tell the control which graph to display
AvGraphCtl1.Root = m_root
AvGraphCtl1.GraphPath = "graph:/graph"
'Uncomment the following three lines to save the current objmodel to a file.
'Dim fileLoader As AvFileLoader
'Set fileLoader = New AvFileLoader
'Call fileLoader.SaveAs(m_root, "C:/sine2d.xml", False)
End Sub
Private Sub Recalc()
Dim x, y, z, d, dist As Single

d = m_fDropoff * m_fDropoff
For i = 0 To numRows - 1
y = i
y = y / (numRows - 1)
y = y * 2# - 1#
For j = 0 To numCols - 1
x = j
x = x / (numCols - 1)
x = x * 2# - 1#
dist = Sqr(x * x + y * y)
m_fvData(i, j) = Cos(dist * m_fFreq * fPi) * m_fAmp / Exp(dist * d * 10)
Next j
Next i
Call m_data.WriteData(m_fvData)
Call AvGraphCtl1.Update
' Addition : copy data point to avis2d OCX'
Avis2D1.CopyArrayData (m_fvData)
Avis2D1.Update
' Addition : set the palette id to user_defined
Avis2D1.PaletteId = User_Defined

End Sub

Private Sub HScroll1_Scroll()
m_fDropoff = HScroll1.Value / 100#
Text1.Text = m_fDropoff
Call Recalc
End Sub

Just added some more lines to the codes: attached is the output showing the vertical progression in the case of CVF and horizontal one in the case of IVF.

Thanks

Yitzak

Const numRows = 200
Const numCols = 200
Const fPi = 3.14159265358979
Dim m_root As IAvGroup
Dim m_data As IAvDataset
' ***Addition*** : Pdata is the palettes data set
Dim m_Pdata As IAvDataset
Dim m_fAmp As Single
Dim m_fDropoff As Single
Dim m_fFreq As Single
Dim m_fvData() As Single
Dim m_PvData() As Long

Private Sub Form_Load()
ReDim m_fvData(numRows - 1, numCols - 1)
m_fAmp = 1#
m_fDropoff = 0.4
m_fFreq = 3#
Set m_root = New AvGroup
m_root.Name = "root"
Set m_data = m_root.Datasets.CreateDataset("data")
' ***Addition*** : Palettes data set creation
Set m_Pdata = m_root.Datasets.CreateDataset("Pdata")
Dim graph As IAvGraph3D
Dim light As Single
Set graph = m_root.Graphs.CreateGraph3D("graph")
'The default Origin and Size is -1 and 2 in X, Y, and Z
'Shortening the height of the box a bit will look better for
' most height plot graphs
graph.Transform.Origin(AV_ZCOORD) = -0.6
graph.Transform.Size(AV_ZCOORD) = 1.2
Avis2D1.ZScale = 0.5
'Draw a green rectangular box around the box
graph.Border.Color = m_root.Context.RGBA(0, 255, 0, 255)
graph.Border.Visible = False
Avis2D1.ShowPalette = True
Avis2D1.ShowAxis = False
Avis2D1.Shading = SmoothShading
Avis2D1.Lighting = True
Avis2D1.ShowPaletteLabels = True
Avis2D1.HighLight = True
Avis2D1.GraphType = HeightPlot
Avis2D1.TextureMode = NeverTexture
Avis2D1.PaletteAutoAdjust = True
' Move the camera in a bit
graph.Camera.Viewpoint(AV_XCOORD) = 2#
graph.Camera.Viewpoint(AV_YCOORD) = 2#
graph.Camera.Viewpoint(AV_ZCOORD) = 3

' ***Addition set the same viewpoint for AVis2d
Avis2D1.CamXPos = 2#
Avis2D1.CamYPos = 2#
Avis2D1.CamZPos = 3#

' Create a height plot
Dim hplot As IAvHeightPlot
Set hplot = graph.Plots.CreatePlot("hplot", AV_HEIGHTPLOT)
' Tell the height plot to get its data from the dataset we created using m_fvData
hplot.XYSource = "/data"
' ***Addition*** : Tell the height plot to get its Palette data from the dataset we created
' using m_PvData
hplot.Color.ColorSource = "/Pdata"
hplot.Color.ColorSourceFormat = AV_RGBA
'Set the surface color to red.
' Alternatively, we could set up a palette and map points on the plot to different
' colors based on the height.

ReDim m_PvData(255) As Long
For i = 0 To 255
m_PvData(i) = m_root.Context.RGBA(255, 255 - i, 0, 255)
Next i
' ***Addition*** copy Palettes to both IFV and CVF
m_Pdata.WriteData (m_PvData)
Avis2D1.CopyPaletteData (m_PvData)

'Set the position to be just inside the parent graph region
hplot.Position.Origin(AV_XCOORD) = -1#
hplot.Position.Origin(AV_YCOORD) = -1#
hplot.Position.Origin(AV_ZCOORD) = -0.5
hplot.Position.Size(AV_XCOORD) = 2#
hplot.Position.Size(AV_YCOORD) = 2#
hplot.Position.Size(AV_ZCOORD) = 1#
'Set the transform to cover the index values of the array in the
'X and Y directions. And to the range [-1.0, 1.0] in the Z (since we
' know m_fvData values won't fall outside that range).hplot.Transform.Origin(AV_XCOORD) = 0#
hplot.Transform.Origin(AV_YCOORD) = 0#
hplot.Transform.Origin(AV_ZCOORD) = -1#
hplot.Transform.Size(AV_XCOORD) = numRows
hplot.Transform.Size(AV_YCOORD) = numCols
hplot.Transform.Size(AV_ZCOORD) = 2#
'Adjust the number of grid lines proportionally with the array size
hplot.Grid.ColSpacing = 5
hplot.Grid.RowSpacing = 5
hplot.Grid.Visible = True
'Set up form
Text1.Text = m_fDropoff
HScroll1.Value = m_fDropoff * 100#

'Update data array, Dataset

Call Recalc
'Tell the control which graph to display
AvGraphCtl1.Root = m_root
AvGraphCtl1.GraphPath = "graph:/graph"
'Uncomment the following three lines to save the current objmodel to a file.
'Dim fileLoader As AvFileLoader
'Set fileLoader = New AvFileLoader
'Call fileLoader.SaveAs(m_root, "C:/sine2d.xml", False)
End Sub
Private Sub Recalc()
Dim x, y, z, d, dist As Single

d = m_fDropoff * m_fDropoff
For i = 0 To numRows - 1
y = i
y = y / (numRows - 1)
y = y * 2# - 1#
For j = 0 To numCols - 1
x = j
x = x / (numCols - 1)
x = x * 2# - 1#
dist = Sqr(x * x + y * y)
m_fvData(i, j) = Cos(dist * m_fFreq * fPi) * m_fAmp / Exp(dist * d * 10)
Next j
Next i
Call m_data.WriteData(m_fvData)
Call AvGraphCtl1.Update
' Addition : copy data point to avis2d OCX'
Avis2D1.CopyArrayData (m_fvData)
Avis2D1.Update
' Addition : set the palette id to user_defined
Avis2D1.PaletteId = User_Defined

End Sub

Private Sub HScroll1_Scroll()
m_fDropoff = HScroll1.Value / 100#
Text1.Text = m_fDropoff
Call Recalc
End Sub

Hi Yitzak,

That's interesting that you have the Compaq AV and Intel AV controls hosted in the same form! Your project is a good resource for any AV/VB6developers switching between the two versions.

You came up with the correct code for setting up the palette dataset. The only problem is when you setup the properties for the height plot. You had:

hplot.Color.ColorSource = "/Pdata"

and

hplot.Color.ColorSourceFormat = AV_RGBA

I.e. your setting the color source to the palette dataset and saying the format of the colorsource is RGBA (i.e. 4 bytes that give the red-green-blue-alpha color components).

But actually what you want is to use the same ColorSource as the XYSource of the heightplot. i.e.

hplot.Color.ColorSource = "/data"

Now "/data" is a 2d dataset of floating point values with the min val of -1 and a max value of 1. We want to map this range of values into colors using the palette we setup. So add these lines:

hplot.Color.PaletteDataSource = "/Pdata"
hplot.Color.ColorSourceFormat = AV_RANGE
hplot.Color.PaletteRangeStart = -1#
hplot.Color.PaletteRangeEnd = 1#

This gives a result like the attached jpeg. Is that what you are looking for?

Let us know if you have any other questions regarding CVF ->IVF migration.

John

Thanks John, that's what I expected. Hoever, its interesting that IntelAV can also render color palettes horizontally.

Yitzak

I'm not sure that's a feature!Forheightplotsit's assume that the shape (i.e. rank and extents) of the ColorSource dataset match those of the Palette dataset. In your example we had a 2D XYSource paired with a 1D colorsource, so the result is not well defined. I suspect that the code is just reusing the same color source values for each row of the plot, hence the "horizontal color palette".

John

Leave a Comment

Please sign in to add a comment. Not a member? Join today