home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
peter
/
ER
/
BP_trend.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
1998-07-07
|
25KB
|
885 lines
/*
BP_trend.cc
*/
#include "BP_trend.h"
#include <iostream.h>
#include <math.h>
//#include <wtpp.h>
#include "v3dSystem.h"
///////////////////////////
// BPTrend //
/////////////////////////
#define REMOBJ // Remove objects from simulation instead of hiding.
#define NOPERFORMER // Turn off Performer optimizations.
//#define FRAMERATE // Print the frame rate at certain intervals.
const int BPTrend::Waveform_Tess = 3; // Tesselation of the waveform objects.
const int BPTrend::Lead_Object_Tess = 4;
// Tesselation of the lead object.
const int BPTrend::Default_Num_Increments = 80;
// Default number of trend increments on an BP trend object.
const int BPTrend::Minimum_Num_Increments = 10;
// Minimum number of trend increments on an BP trend object.
// Initial colors for the various parts of an BP trend object.
const v3dColor BPTrend::BP_trend_background_color = v3dColor (0, 0, 255);
const v3dColor BPTrend::BP_trend_waveform_color = v3dColor (255, 255, 255);
const v3dColor BPTrend::BP_trend_frame_color = v3dColor (255, 255, 255);
const v3dColor BPTrend::BP_trend_lead_object_color = v3dColor (0, 255, 0);
const v3dColor BPTrend::BP_trend_threshold_color = v3dColor (255, 0, 0);
///////////////
// CREATORS //
/////////////
BPTrend::BPTrend (const BPTrend& trend)
{
initialize (trend.BP_driver_, trend.length_, trend.height_,
trend.depth_, trend.num_increments_);
paused_ = trend.paused_;
current_x_ = trend.current_x_;
last_x_ = trend.last_x_;
last_y_ = trend.last_y_;
current_index_ = trend.current_index_;
hide_index_ = trend.hide_index_;
last_drv_index_ = trend.last_drv_index_;
for (int i = 0; i < num_increments_; ++i)
plot_values_[i] = trend.plot_values_[i];
MoveAbsolute (trend.GetAbsolutePosition());
SetAbsoluteOrientation (trend.GetAbsoluteOrientation());
}
// BPTrend::Copy()
// Creates a copy of the trend and returns a pointer to the new trend.
#ifndef SGICC
inline BPTrend*
#else
v3dEntity*
#endif
BPTrend::Copy() const
{
return new BPTrend (*this);
}
///////////////////
// MANIPULATORS //
/////////////////
// BPTrend::initialize
// Initializer for BPTrend object, called by a BPTrend constructor.
// Registers this object as a receiver of BP data from an
// BPDataSender object.
// Parameters:
// float length
// Horizontal extent of the BP trend.
// float height
// Vertical extent of the BP trend.
// float depth
// Thickness of the BP object.
// int num_increments
// Number of increments to show along the length of
// the trend.
void
BPTrend::initialize (BPTrendDriver *BP_driver,
float length, float height, float depth,
int num_increments)
{
// Assign the BP driver.
BP_driver_ = BP_driver;
length_ = length;
height_ = height;
depth_ = depth;
num_increments_ = num_increments;
waveform_radius_ = height_ / 100;
// Calculate trend variables based on the client's specifications.
calculate_plot_variables();
// Request the range of data from the BP sender object, and calculate
// the range and scale to be used for the trend.
data_range_ = BP_driver_->GetDataRange();
calculate_scale_variables();
// Initialize variables used in determining trendting position.
current_x_ = increment_length_;
last_x_ = last_y_ = 0;
current_index_ = 0;
last_drv_index_ = 0;
// Register this object's event handler with the BP data sender.
RegisterEventHandler(BP_driver_, BP_TREND_DATA_UPDATE,
&BP_update_callback, 0);
paused_ = false; // The BP trend doesn't start out paused.
// Create the background and frame.
create_background_and_frame ();
// Create the baseline and other necessary objects.
create_baseline();
}
// BPTrend::Reset
// Resets the BP trend. All increments are hidden and the lead object
// is returned to the origin.
void
BPTrend::Reset()
{
// Hide the plot line.
for (int i = 0; i < num_increments_; ++i) {
baseline_array_[i]->Disable();
}
plot_values_[0] = 0;
plot_values_[num_increments_-1] = 0;
// Initialize variables used in determining plotting position.
current_x_ = increment_length_;
last_x_ = last_y_ = 0;
current_index_ = 0;
last_drv_index_ = 0;
// Move the lead object to the origin.
lead_object_->Move (v3dPos(increment_length_ / 2, 0, 0), *origin_);
}
// BPTrend::Pause
// Pause the update of the BP trend. No new data will be shown until
// the trend is unpaused.
void
BPTrend::Pause()
{
paused_ = true;
// ADD: pausing!
}
// BPTrend::Unpause
// Restart the update of the BP trend.
void
BPTrend::Unpause()
{
paused_ = false;
// ADD: unpausing!
}
// BPTrend::calculate_plot_variables
// Calculate trend variables based on the client's specifications.
void
BPTrend::calculate_plot_variables()
{
waveform_radius_ = height_ / 100;
hide_interval_ = num_increments_ / 8;
half_depth_ = depth_ / 2;
lead_object_radius_ = waveform_radius_ * 3;
frame_width_ = length_ > height_ ? length_ / 40 : height_ / 40;
background_depth_ = depth_ / 5;
vert_buffer_ = frame_width_ * 2;
horiz_buffer_ = length_ / 100;
baseline_length_ = length_ - 2 * frame_width_ - 2 * horiz_buffer_;
baseline_X_ = frame_width_ + horiz_buffer_;
baseline_Y_ = height_ / 2;
increment_length_ = baseline_length_ / num_increments_;
}
// BPTrend::calculate_scale_variables
// Calculate the vertical range and scale of the trend based on trend
// variables and the range of data sent by the BP data sender.
void
BPTrend::calculate_scale_variables()
{
vert_plot_range_ = height_ - 2 * frame_width_ - 2 * vert_buffer_;
#if 0
BP_TREND_DATA_TYPE range = data_range_.maximum_value -
(data_range_.minimum_value > 0 ? 0 : data_range_.minimum_value);
#endif
BP_TREND_DATA_TYPE range;
if (fabsf(data_range_.maximum_value) > fabsf(data_range_.minimum_value))
range = 2 * fabsf(data_range_.maximum_value);
else
range = 2 * fabsf(data_range_.minimum_value);
if (range > 0)
vert_scale_ = vert_plot_range_ / range;
else
vert_scale_ = vert_plot_range_;
cerr << "max value: " << data_range_.maximum_value <<
" min value: " << data_range_.minimum_value <<
" vert scale: " << vert_scale_ << endl;
}
// BPTrend::create_background_and_frame
// Creates the bounding box, background and frame objects for the BP trend.
void
BPTrend::create_background_and_frame ()
{
// Create the bounding box that will serve as the root of the object
// hierarchy for the component objects of the BP.
bounding_box_ = new v3dBlockObject (length_, height_, depth_);
bounding_box_->Hide();
// Create the BP object background.
background_ = new v3dBlockObject (length_, height_, background_depth_);
background_->MoveAbsolute (v3dPos (0, 0,
(depth_ - background_depth_ / 2)));
// The background is initially hidden.
HideBackground();
// Create the BP object frame.
frame_bottom_ = new v3dBlockObject (length_, frame_width_, depth_);
frame_top_ = new v3dBlockObject (length_, frame_width_, depth_);
frame_left_ = new v3dBlockObject (frame_width_, height_, depth_);
frame_right_ = new v3dBlockObject (frame_width_, height_, depth_);
frame_bottom_->MoveAbsolute (v3dPos (0, (height_ - frame_width_) / 2,
0));
frame_top_->MoveAbsolute (v3dPos (0, (height_ - frame_width_) / -2,
0));
frame_left_->MoveAbsolute (v3dPos ((length_ - frame_width_) / -2,
0, 0));
frame_right_->MoveAbsolute (v3dPos ((length_ - frame_width_) / 2,
0, 0));
// Add the frame and the background to the bounding box.
bounding_box_->Add (background_);
bounding_box_->Add (frame_bottom_);
bounding_box_->Add (frame_top_);
bounding_box_->Add (frame_left_);
bounding_box_->Add (frame_right_);
// Set the colors of the various elements.
background_->SetColor(BP_trend_background_color);
frame_bottom_->SetColor(BP_trend_frame_color);
frame_top_->SetColor(BP_trend_frame_color);
frame_left_->SetColor(BP_trend_frame_color);
frame_right_->SetColor(BP_trend_frame_color);
#ifndef NOPERFORMER
// Specify Performer rendering.
WTobject_addperformer (
(WTobject *)background_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_bottom_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_top_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_left_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_right_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
#endif // NOPERFORMER
// Set the BP's implementation object to the background's
// implementation object.
imp = bounding_box_->GetImplement();
// The frame is initially shown.
ShowFrame();
}
void
BPTrend::scale_background_and_frame(const v3dVector &factors,
const v3dPos& point)
{
#ifndef NOPERFORMER
// Temporarirly disable Performer rendering.
WTobject_deleteperformer ((WTobject *)background_->GetHandler());
WTobject_deleteperformer ((WTobject *)frame_bottom_->GetHandler());
WTobject_deleteperformer ((WTobject *)frame_top_->GetHandler());
WTobject_deleteperformer ((WTobject *)frame_left_->GetHandler());
WTobject_deleteperformer ((WTobject *)frame_right_->GetHandler());
#endif // NOPERFORMER
bounding_box_->Scale (factors, point);
background_->Scale (factors, point);
frame_top_->Scale (factors, point);
frame_bottom_->Scale (factors, point);
frame_left_->Scale (factors, point);
frame_right_->Scale (factors, point);
#ifndef NOPERFORMER
// Reinstate Performer rendering.
WTobject_addperformer (
(WTobject *)background_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_bottom_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_top_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_left_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
WTobject_addperformer (
(WTobject *)frame_right_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
#endif // NOPERFORMER
}
void
BPTrend::delete_background_and_frame()
{
// delete bounding_box_;
delete background_;
delete frame_left_;
delete frame_right_;
delete frame_top_;
delete frame_bottom_;
}
// BPTrend::create_baseline
// Creates the BP trend's baseline and all objects associated with it.
void
BPTrend::create_baseline()
{
// Create the baseline origin for the waveform.
origin_ = new v3dBlockObject (1, 1, 1);
origin_->MoveAbsolute (v3dVector(baseline_X_ - length_ / 2,
-baseline_Y_ + height_ / 2, 0));
#ifdef REMOBJ
origin_->Disable();
#else
origin_->Hide();
#endif
// Add the baseline origin to the background hierarchy.
bounding_box_->Add (origin_);
// Create the high and low threshold boundary lines.
high_threshold_line_ = new v3dCylinderObject (baseline_length_,
waveform_radius_, Waveform_Tess);
low_threshold_line_ = new v3dCylinderObject (baseline_length_,
waveform_radius_, Waveform_Tess);
bounding_box_->Add (high_threshold_line_);
bounding_box_->Add (low_threshold_line_);
v3dLineObject guide_line (v3dPos(0, 0, 0), v3dPos (1, 0, 0),
waveform_radius_, Waveform_Tess);
high_threshold_line_->SetOrientation(guide_line.GetAbsoluteOrientation());
low_threshold_line_->SetOrientation(guide_line.GetAbsoluteOrientation());
high_threshold_line_->SetColor(BP_trend_threshold_color);
low_threshold_line_->SetColor(BP_trend_threshold_color);
// Create the lead object.
float current_X = baseline_X_ - length_ / 2,
half_increment = increment_length_ / 2;
lead_object_ = new v3dSphereObject (lead_object_radius_,
Lead_Object_Tess, Lead_Object_Tess);
origin_->Add (lead_object_);
// lead_object_->MoveAbsolute (v3dVector (current_X + half_increment,
// -baseline_Y_, half_depth_));
lead_object_->Move (v3dPos(increment_length_ / 2, 0, 0), *origin_);
lead_object_->SetColor(BP_trend_lead_object_color);
#ifndef NOPERFORMER
WTobject_addperformer (
(WTobject *)lead_object_->GetHandler(),
FALSE, FALSE, FALSE, FALSE, NULL, NULL);
#endif // NOPERFORMER
// Create the individual baseline trend objects.
baseline_array_ = new (v3dLineObject *) [num_increments_];
plot_values_ = new BP_TREND_DATA_TYPE [num_increments_];
// WTp3 align_vec = { 1, 0, 0 };
v3dVector inc_vec (increment_length_, 0, 0);
// v3dPos from_pos (current_X, -baseline_Y_, half_depth_);
v3dPos from_pos (current_X, 0, 0);
for (int ci = 0; ci < num_increments_; ++ci) {
plot_values_[ci] = 0;
from_pos.x (current_X);
baseline_array_[ci]
= new v3dLineObject (from_pos, from_pos + inc_vec,
waveform_radius_, Waveform_Tess);
// CHANGE: this!
baseline_array_[ci]->SetPoints(*origin_, from_pos, from_pos + inc_vec);
#if 0
baseline_array_[ci]
= new v3dLineObject (
((v3dEntity *)origin_)->GetAbsolutePosition(from_pos),
((v3dEntity *)origin_)->GetAbsolutePosition(from_pos + inc_vec),
waveform_radius_, Waveform_Tess);
#endif
// Add a baseline trend object to the baseline origin.
origin_->Add (baseline_array_[ci]);
#ifdef REMOBJ
baseline_array_[ci]->Disable();
#else
baseline_array_[ci]->Hide();
#endif
// Color the baseline objects.
baseline_array_[ci]->SetColor(BP_trend_waveform_color);
current_X += increment_length_;
}
lead_object_->SetColor(BP_trend_lead_object_color);
// Move the threshold lines into place.
high_threshold_line_->Translate(v3dDir (0,
- data_range_.high_threshold_value * vert_scale_, 0));
low_threshold_line_->Translate(v3dDir (0,
- data_range_.low_threshold_value * vert_scale_, 0));
}
void
BPTrend::delete_baseline()
{
for (int ci = 0; ci < num_increments_; ci++)
delete baseline_array_[ci];
delete high_threshold_line_;
delete low_threshold_line_;
delete lead_object_;
delete origin_;
}
// BPTrend::BP_update_callback
// Event handler callback function, notified every cycle to request
// the latest data from the BP driver.
void
BPTrend::BP_update_callback (const v3dEventMessage *message)
{
#ifdef FRAMERATE
static int frame_count = 0;
if (++frame_count == 40) {
cerr << "Frame rate: " << WTuniverse_framerate() << endl;
frame_count = 0;
}
#endif // FRAMERATE
((BPTrend *)message->GetEventReceiver())->plot_new_data ();
}
// BPTrend::plot_new_data
// Copies the latest data from the BP driver, then trends any new
// data on the BP.
void
BPTrend::plot_new_data ()
{
int current_drv_index = BP_driver_->GetCurrentDataIndex();
// If there's no new data to be displayed, then just return.
if (last_drv_index_ == current_drv_index)
return;
int new_index = current_index_;
bool recalculate_hr = false;
// Copy the data from the BP driver.
do {
last_drv_index_ =
BP_driver_->GetNextDataIndex(last_drv_index_);
plot_values_[new_index++] =
BP_driver_->data_list[last_drv_index_];
if (new_index >= num_increments_)
new_index = 0;
} while (last_drv_index_ != current_drv_index);
// Plot the new data.
plot_data (new_index);
current_index_ = new_index;
}
// BPTrend::plot_data
// Plots the BP data on the waveform up to the new index specified.
// Parameters:
// int new_index
// The last index of the trend data to be shown.
void
BPTrend::plot_data (int new_index)
{
float this_y, diff_y;
v3dPos new_pos,
last_pos = v3dVector(last_x_, -(last_y_), 0);
while (current_index_ != new_index) {
this_y = plot_values_[current_index_] * vert_scale_;
diff_y = this_y - last_y_;
new_pos = v3dVector(current_x_, -(this_y), 0);
hide_index_ = (current_index_ + hide_interval_)
% num_increments_;
baseline_array_[hide_index_]->Disable();
// cout << "data:" << this_y << " diff: " << diff_y << " ";
baseline_array_[current_index_]->SetPoints(*origin_,
last_pos, new_pos);
baseline_array_[current_index_]->Enable();
// Color the trend.
baseline_array_[current_index_]->SetColor(
BP_trend_waveform_color);
last_y_ = this_y;
last_pos = new_pos;
++current_index_;
if (current_index_ >= num_increments_) {
current_index_ = 0;
current_x_ = increment_length_;
last_x_ = 0;
last_pos.x(0);
} else {
last_x_ = current_x_;
current_x_ += increment_length_;
}
}
lead_object_->Move(new_pos);
}
void
BPTrend::scale_baseline (const v3dVector &factors, const v3dPos& point)
{
origin_->Scale(factors, point);
high_threshold_line_->Scale (factors, point);
low_threshold_line_->Scale (factors, point);
// Move the threshold lines into place.
high_threshold_line_->Move(v3dDir (0,
- data_range_.high_threshold_value * vert_scale_, 0));
low_threshold_line_->Move(v3dDir (0,
- data_range_.low_threshold_value * vert_scale_, 0));
float current_x = increment_length_, last_x = 0;
float last_y = plot_values_[num_increments_ - 1] * vert_scale_;
for (int i = 0; i < num_increments_; ++i) {
float this_y = plot_values_[i] * vert_scale_,
diff_y = this_y - last_y;
#if 0
v3dPos new_pos = origin_->GetAbsolutePosition()
+ v3dVector(current_x, -(this_y), 0),
last_pos = origin_->GetAbsolutePosition()
+ v3dVector(last_x, -(last_y), 0);
#endif
v3dPos new_pos = v3dVector(current_x, -(this_y), 0),
last_pos = v3dVector(last_x, -(last_y), 0);
delete baseline_array_[i];
baseline_array_[i]
= new v3dLineObject (last_pos, new_pos,
waveform_radius_, Waveform_Tess);
origin_->Add (baseline_array_[i]);
// CHANGE: this!
baseline_array_[i]->SetPoints(*origin_, last_pos, new_pos);
// baseline_array_[i]->SetPoints(last_pos, new_pos);
last_x = current_x;
last_y = this_y;
current_x += increment_length_;
}
// Recalculate trendting position variables.
// last_x_ *= factors.x();
// current_x_ *= factors.x();
// if (current_index_ == 0)
// last_x_ = 0;
// else
last_x_ = current_index_ * increment_length_;
current_x_ = (current_index_+1) * increment_length_;
last_y_ *= factors.y();
// last_y_ = plot_values_ [current_index_] * vert_scale_;
delete lead_object_;
lead_object_ = new v3dSphereObject (lead_object_radius_,
Lead_Object_Tess, Lead_Object_Tess);
origin_->Add(lead_object_);
lead_object_->Move(v3dVector(last_x_, -(last_y_), 0));
lead_object_->SetColor(BP_trend_lead_object_color);
// lead_object_->Move(origin_->GetAbsolutePosition()
// + v3dVector(last_x_, -(last_y_), 0));
}
// BPTrend::fix_hide_interval
// Re-hides objects along the hide interval to fix any errors introduced
// when the sweep speed was changed.
void
BPTrend::fix_hide_interval ()
{
hide_interval_ = num_increments_ / 8;
int current_index = current_index_;
for (int i = 0; i < hide_interval_; ++i, ++current_index) {
if (current_index >= num_increments_)
current_index = 0;
#ifdef REMOBJ
baseline_array_[current_index]->Disable();
#else
baseline_array_[current_index]->Hide();
#endif
}
}
// BPTrend::extend_baseline
// Extends the baseline to the number of increments specified.
// The old baseline array is copied to a new baseline array, and the
// new elements in the array are initialized with flat baseline
// elements.
// Parameters:
// unsigned int old_increment_num
// Old number of increments on the the baseline.
// unsigned int new_increment_num
// New number of increments on the the baseline.
void
BPTrend::extend_baseline (unsigned int old_increment_num,
unsigned int new_increment_num)
{
ASSERT (new_increment_num >= old_increment_num);
v3dLineObject **new_baseline_array
= new (v3dLineObject *) [new_increment_num];
BP_TREND_DATA_TYPE *new_plot_values
= new BP_TREND_DATA_TYPE [new_increment_num];
// Copy the old baseline elements into the new array.
for (int i = 0; i < old_increment_num; ++i) {
new_baseline_array[i] = baseline_array_[i];
new_plot_values [i] = plot_values_ [i];
}
delete [] baseline_array_;
delete [] plot_values_;
// Create new, flat baseline objects.
v3dVector inc_vec (increment_length_, 0, 0);
float current_X = old_increment_num * increment_length_;
v3dPos from_pos (current_X, 0, 0);
// v3dPos from_pos (current_X, -baseline_Y_, half_depth_);
for (int ci = old_increment_num; ci < new_increment_num; ++ci) {
new_plot_values[ci] = 0;
from_pos.x (current_X);
#if 0
new_baseline_array[ci]
= new v3dLineObject (
((v3dEntity *)origin_)->GetAbsolutePosition(from_pos),
((v3dEntity *)origin_)->GetAbsolutePosition(from_pos + inc_vec),
waveform_radius_, Waveform_Tess);
#endif
new_baseline_array[ci]
= new v3dLineObject (from_pos, from_pos + inc_vec,
waveform_radius_, Waveform_Tess);
// CHANGE: this!
new_baseline_array[ci]->SetPoints(*origin_, from_pos, from_pos + inc_vec);
// Add a baseline trend object to the baseline origin.
origin_->Add (new_baseline_array[ci]);
#if 0
#ifdef REMOBJ
new_baseline_array[ci]->Disable();
#else
new_baseline_array[ci]->Hide();
#endif
#endif
// Color the baseline objects.
new_baseline_array[ci]->SetColor(BP_trend_waveform_color);
current_X += increment_length_;
}
baseline_array_ = new_baseline_array;
plot_values_ = new_plot_values;
}
// BPTrend::shrink_baseline
// Shrinks the baseline to the number of increments specified.
// The old baseline array is copied to a new baseline array, leaving
// out extra elements farthest from the leading edge of the graph.
// Parameters:
// unsigned int old_increment_num
// Old number of increments on the the baseline.
// unsigned int new_increment_num
// New number of increments on the the baseline.
void
BPTrend::shrink_baseline (unsigned int old_increment_num,
unsigned int new_increment_num)
{
ASSERT (new_increment_num <= old_increment_num);
v3dLineObject **new_baseline_array
= new (v3dLineObject *) [new_increment_num];
BP_TREND_DATA_TYPE *new_plot_values
= new BP_TREND_DATA_TYPE [new_increment_num];
// Copy the old baseline elements into the new array.
int start_index, finish_index;
if (current_index_ >= new_increment_num) {
start_index = current_index_ - new_increment_num + 1;
finish_index = current_index_ + 1;
current_index_ = new_increment_num - 1;
current_x_ = current_index_ * increment_length_;
last_x_ = (current_index_-1) * increment_length_;
} else {
start_index = 0;
finish_index = new_increment_num;
}
for (int i = 0; i < start_index; ++i)
delete baseline_array_[i];
for (int i = start_index; i < finish_index; ++i) {
new_baseline_array[i-start_index] = baseline_array_[i];
new_plot_values [i-start_index] = plot_values_ [i];
}
for (int i = finish_index; i < old_increment_num; ++i)
delete baseline_array_[i];
delete [] baseline_array_;
delete [] plot_values_;
baseline_array_ = new_baseline_array;
plot_values_ = new_plot_values;
}
// BPTrend::MoveFrontLowerLeftCorner
// Move the entire BP trend.
// Parameters:
// v3dPos& pos
// New location for the front lower left corner.
void
BPTrend::MoveFrontLowerLeftCorner (const v3dPos& pos)
{
GetObject()->MoveAbsolute (v3dVector (pos.x() + length_ / 2,
pos.y() - height_ / 2,
pos.z() + depth_ / 2));
}
void
BPTrend::HideFrame ()
{
frame_left_->Hide();
frame_right_->Hide();
frame_top_->Hide();
frame_bottom_->Hide();
frame_hidden_ = true;
}
void
BPTrend::ShowFrame ()
{
frame_left_->Show();
frame_right_->Show();
frame_top_->Show();
frame_bottom_->Show();
frame_hidden_ = false;
}
// BPTrend::Scale
// Stretches the BP trend about a point by the given factors.
void
BPTrend::Scale (const v3dVector &factors, const v3dPos& point)
{
scale_background_and_frame(factors, point);
v3dDim dim = bounding_box_->GetSize();
length_ = dim.x();
height_ = dim.y();
depth_ = dim.z();
calculate_plot_variables();
calculate_scale_variables();
scale_baseline(factors, point);
fix_hide_interval();
}
// BPTrend::SetSize
// Sets the exact size of the BP.
inline void
BPTrend::SetSize (const v3dDim &dimensions)
{
Scale (v3dVector (dimensions.x() / length_,
dimensions.y() / height_,
dimensions.z() / depth_));
}
// BPTrend::ChangeSweepSpeed
// Increases or decreases the sweep speed of the BP trend by the
// specified factor.
// The number of increments on the baseline is either increased or
// decreased, and the baseline as a whole is scaled up or down.
// Parameters:
// float change_factor
// Factor to change the speed by. For example,
// 1 = no change,
// 1.05 = 5% faster,
// 0.95 = 5% slower
void
BPTrend::ChangeSweepSpeed (float change_factor)
{
int new_num_increments = (int)trunc (num_increments_ * change_factor);
if (new_num_increments < Minimum_Num_Increments)
new_num_increments = Minimum_Num_Increments;
if (change_factor > 1)
extend_baseline (num_increments_, new_num_increments);
else
shrink_baseline (num_increments_, new_num_increments);
num_increments_ = new_num_increments;
increment_length_ = baseline_length_ / new_num_increments;
scale_baseline (v3dVector (1/change_factor, 1, 1),
origin_->GetAbsolutePosition());
fix_hide_interval();
}
// BPTrend::~BPTrend
BPTrend::~BPTrend ()
{
delete_baseline();
delete_background_and_frame();
}
void
BPTrend::switch_data ()
{
last_drv_index_ = 0;
data_range_ = BP_driver_->GetDataRange();
calculate_scale_variables();
}
bool
BPTrend::CorrectUp()
{
if (BP_driver_->CorrectUp()) {
last_drv_index_ = 0;
return true;
} else
return false;
}
bool
BPTrend::CorrectDown()
{
if (BP_driver_->CorrectDown()) {
last_drv_index_ = 0;
return true;
} else
return false;
}