Commit 1a3eb3dc authored by bonnell's avatar bonnell

Add 'use foreground color' and 'line style' options to Line2D annotation...

Add 'use foreground color' and 'line style' options to Line2D annotation object.  Added Line3D annotation object.  Resolves #129, 1360 and 2327

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@26759 18c085ea-50e0-402c-830e-de6fd14e8384
parent f151552f
......@@ -43,6 +43,9 @@
# Brad Whitlock, Fri May 17 11:12:55 PDT 2013
# Link with Objective C library on Mac.
#
# Kathleen Biagas, Mon Jul 13 20:09:58 PDT 2015
# Add Colleagues/avtText3DColleague.C
#
#****************************************************************************/
SET(COLLEAGUES_SOURCES
......@@ -71,6 +74,7 @@ Colleagues/avtAnnotationColleague.C
Colleagues/avtImageColleague.C
Colleagues/avtLegendAttributesColleague.C
Colleagues/avtLine2DColleague.C
Colleagues/avtLine3DColleague.C
Colleagues/avtText2DColleague.C
Colleagues/avtText3DColleague.C
Colleagues/avtTimeSliderColleague.C
......
......@@ -47,6 +47,7 @@
#include <avtImageColleague.h>
#include <avtLegendAttributesColleague.h>
#include <avtLine2DColleague.h>
#include <avtLine3DColleague.h>
#include <avtText2DColleague.h>
#include <avtText3DColleague.h>
#include <avtTimeSliderColleague.h>
......@@ -380,6 +381,9 @@ VisWinAnnotations::SetFrameAndState(int nFrames,
// Brad Whitlock, Mon Mar 2 15:33:25 PST 2009
// I added code to set the new annotation's time scale and offset.
//
// Kathleen Biagas, Mon Jul 13 20:09:09 PDT 2015
// Added Line3D.
//
// ****************************************************************************
bool
......@@ -422,10 +426,13 @@ VisWinAnnotations::AddAnnotationObject(int annotType, const std::string &annotNa
case 3: // Line 2D
annot = new avtLine2DColleague(mediator);
break;
case 7: // Image
case 4: // Line 3D
annot = new avtLine3DColleague(mediator);
break;
case 8: // Image
annot = new avtImageColleague(mediator);
break;
case 8: // LegendAttributes
case 9: // LegendAttributes
annot = new avtLegendAttributesColleague(mediator);
break;
default:
......
......@@ -56,6 +56,7 @@
#include <vtkRenderer.h>
#include <AnnotationObject.h>
#include <LineAttributes.h>
#include <VisWindow.h>
#include <VisWindowColleagueProxy.h>
......@@ -80,6 +81,9 @@
// Brad Whitlock, Tue Jun 28 15:32:03 PST 2005
// Removed the cone sources.
//
// Kathleen Biagas, Mon Jul 13 09:41:56 PDT 2015
// Add useForegroundForLineColor.
//
// ****************************************************************************
avtLine2DColleague::avtLine2DColleague(VisWindowColleagueProxy &m):
avtAnnotationColleague(m),
......@@ -95,6 +99,7 @@ avtLine2DColleague::avtLine2DColleague(VisWindowColleagueProxy &m):
endArrowStyle(0)
{
addedToRenderer = false;
useForegroundForLineColor = true;
// Create a float array which represents the points.
vtkFloatArray* pcoords = vtkFloatArray::New();
......@@ -160,7 +165,7 @@ avtLine2DColleague::avtLine2DColleague(VisWindowColleagueProxy &m):
// Set a default color.
double fgColor[3];
mediator.GetForegroundColor(fgColor);
actor->GetProperty()->SetColor(fgColor[0], fgColor[1], fgColor[2]);
SetForegroundColor(fgColor[0], fgColor[1], fgColor[2]);
// Set default opacity.
actor->GetProperty()->SetOpacity(1.);
......@@ -490,13 +495,45 @@ avtLine2DColleague::SetOptions(const AnnotationObject &annot)
lineData->GetPoints()->SetPoint(0, p0[0], p0[1], 0.);
lineData->GetPoints()->SetPoint(1, p1[0], p1[1], 0.);
actor->GetProperty()->SetLineWidth(annot.GetColor2().Red());
actor->GetProperty()->SetLineWidth(annot.GetIntAttribute1()+1);
actor->GetProperty()->SetLineStipplePattern(LineStyle2StipplePattern(Int2LineStyle(annot.GetIntAttribute2())));
ColorAttribute ca = annot.GetColor1();
actor->GetProperty()->SetColor(double(ca.Red()) / 255.,
double(ca.Green()) / 255.,
double(ca.Blue()) / 255.);
actor->GetProperty()->SetOpacity(double(ca.Alpha()) / 255.);
//
// The line color has changed or the useForegroundForTextColor flag
// has changed.
//
if(annot.GetUseForegroundForTextColor() != useForegroundForLineColor ||
annot.GetColor1() != lineColor)
{
// Record the line color that should be used when we're not using
// the foreground text color.
lineColor = annot.GetColor1();
useForegroundForLineColor = annot.GetUseForegroundForTextColor();
// Compute the line opacity.
double lc[4];
lc[3] = double(lineColor.Alpha()) / 255.;
// Set the line color using the foreground color or the line color.
if(useForegroundForLineColor)
{
// Get the foreground color.
double fgColor[3];
mediator.GetForegroundColor(fgColor);
actor->GetProperty()->SetColor(fgColor[0], fgColor[1], fgColor[2]);
}
else
{
// Compute the line color as double.
lc[0] = double(lineColor.Red()) / 255.;
lc[1] = double(lineColor.Green()) / 255.;
lc[2] = double(lineColor.Blue()) / 255.;
actor->GetProperty()->SetColor(lc[0], lc[1], lc[2]);
}
actor->GetProperty()->SetOpacity(double(lc[3]));
}
beginArrowStyle = annot.GetColor2().Green();
endArrowStyle = annot.GetColor2().Blue();
......@@ -581,15 +618,12 @@ avtLine2DColleague::GetOptions(AnnotationObject &annot)
annot.SetPosition(lineData->GetPoints()->GetPoint(0));
annot.SetPosition2(lineData->GetPoints()->GetPoint(1));
double *currColor = actor->GetProperty()->GetColor();
annot.SetColor1(lineColor);
annot.SetUseForegroundForTextColor(useForegroundForLineColor);
annot.SetIntAttribute1(actor->GetProperty()->GetLineWidth()-1);
annot.SetIntAttribute2(LineStyle2Int(StipplePattern2LineStyle(actor->GetProperty()->GetLineStipplePattern())));
ColorAttribute ca;
ca.SetRgba(int((float)currColor[0] * 255),
int((float)currColor[1] * 255),
int((float)currColor[2] * 255),
int((float)actor->GetProperty()->GetOpacity() * 255));
annot.SetColor1(ca);
ca.SetRgb((int) actor->GetProperty()->GetLineWidth(),
ca.SetRgb(0,
beginArrowStyle,
endArrowStyle);
annot.SetColor2(ca);
......@@ -632,3 +666,29 @@ avtLine2DColleague::NoPlots(void)
{
RemoveFromRenderer();
}
// ****************************************************************************
// Method: avtLine2DColleague::SetForegroundColor
//
// Purpose:
// This method is called when the vis window's foreground color changes.
//
// Arguments:
// r,g,b : The new foreground color.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine2DColleague::SetForegroundColor(double r, double g, double b)
{
if(useForegroundForLineColor)
actor->GetProperty()->SetColor(r, g, b);
}
......@@ -64,6 +64,9 @@ class vtkPolyDataMapper2D;
// Brad Whitlock, Tue Jun 28 15:39:27 PST 2005
// Changed so it does not use a cone source.
//
// Kathleen Biagas, Mon Jul 13 09:39:46 PDT 2015
// Add SetForegroundColor.
//
// ****************************************************************************
class VISWINDOW_API avtLine2DColleague : public avtAnnotationColleague
......@@ -83,6 +86,7 @@ public:
virtual void GetOptions(AnnotationObject &annot);
// Methods that are called in response to vis window events.
virtual void SetForegroundColor(double r, double g, double b);
virtual void HasPlots(void);
virtual void NoPlots(void);
......@@ -100,6 +104,8 @@ protected:
int endArrowStyle;
bool addedToRenderer;
bool useForegroundForLineColor;
ColorAttribute lineColor;
bool ShouldBeAddedToRenderer() const;
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2015, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtLine3DColleague.C //
// ************************************************************************* //
#include <avtLine3DColleague.h>
#include <math.h>
#include <snprintf.h>
#include <vtkActor.h>
#include <vtkLineSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <AnnotationObject.h>
#include <LineAttributes.h>
#include <VisWindow.h>
#include <VisWindowColleagueProxy.h>
#include <avtVector.h>
// ****************************************************************************
// Method: avtLine3DColleague::avtLine3DColleague
//
// Purpose:
// Constructor for the avtLine3DColleague class.
//
// Arguments:
// m : The vis window proxy.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
avtLine3DColleague::avtLine3DColleague(VisWindowColleagueProxy &m):
avtAnnotationColleague(m)
{
addedToRenderer = false;
useForegroundForLineColor = true;
lineSource = vtkLineSource::New();
lineSource->SetResolution(1);
lineSource->SetPoint1(0, 0, 0);
lineSource->SetPoint2(1, 1, 0);
lineMapper = vtkPolyDataMapper::New();
lineMapper->SetInputConnection(lineSource->GetOutputPort());
lineActor = vtkActor::New();
lineActor->SetMapper(lineMapper);
lineActor->PickableOff();
// Set a default color.
double fgColor[3];
mediator.GetForegroundColor(fgColor);
SetForegroundColor(fgColor[0], fgColor[1], fgColor[2]);
// Set default opacity.
lineActor->GetProperty()->SetOpacity(1.);
// Set a default line width.
lineActor->GetProperty()->SetLineWidth(1);
lineActor->GetProperty()->SetLineStipplePattern(0xFFFF);
}
// ****************************************************************************
// Method: avtLine3DColleague::~avtLine3DColleague
//
// Purpose:
// Destructor for the avtLine3DColleague class.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
avtLine3DColleague::~avtLine3DColleague()
{
if(lineActor != NULL)
{
lineActor->Delete();
lineActor = NULL;
}
if(lineMapper != NULL)
{
lineMapper->Delete();
lineMapper = NULL;
}
if(lineSource != NULL)
{
lineSource->Delete();
lineSource = NULL;
}
}
// ****************************************************************************
// Method: avtLine3DColleague::AddToRenderer
//
// Purpose:
// This method adds the lineActor to the renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::AddToRenderer()
{
if(!addedToRenderer && ShouldBeAddedToRenderer())
{
mediator.GetCanvas()->AddActor(lineActor);
addedToRenderer = true;
}
}
// ****************************************************************************
// Method: avtLine3DColleague::RemoveFromRenderer
//
// Purpose:
// This method removes the lineActor from the renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::RemoveFromRenderer()
{
if(addedToRenderer)
{
mediator.GetCanvas()->RemoveActor(lineActor);
addedToRenderer = false;
}
}
// ****************************************************************************
// Method: avtLine3DColleague::Hide
//
// Purpose:
// This method toggles the visible flag and either adds or removes the
// lineActor to/from the renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::Hide()
{
SetVisible(!GetVisible());
if(addedToRenderer)
RemoveFromRenderer();
else
AddToRenderer();
}
// ****************************************************************************
// Method: avtLine3DColleague::ShouldBeAddedToRenderer
//
// Purpose:
// This method returns whether or not the lineActor should be added to the
// renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
bool
avtLine3DColleague::ShouldBeAddedToRenderer() const
{
return GetVisible() && mediator.HasPlots();
}
// ****************************************************************************
// Method: avtLine3DColleague::SetOptions
//
// Purpose:
// This method sets the lineActor's properties from the values in the
// annotation object.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::SetOptions(const AnnotationObject &annot)
{
// Get the current options.
AnnotationObject currentOptions;
GetOptions(currentOptions);
lineSource->SetPoint1(const_cast<double*>(annot.GetPosition()));
lineSource->SetPoint2(const_cast<double*>(annot.GetPosition2()));
lineActor->GetProperty()->SetLineWidth(annot.GetIntAttribute1()+1);
lineActor->GetProperty()->SetLineStipplePattern(LineStyle2StipplePattern(
Int2LineStyle(annot.GetIntAttribute2())));
//
// The line color has changed or the useForegroundForTextColor flag
// has changed.
//
if(annot.GetUseForegroundForTextColor() != useForegroundForLineColor ||
annot.GetColor1() != lineColor)
{
// Record the line color that should be used when we're not using
// the foreground text color.
lineColor = annot.GetColor1();
useForegroundForLineColor = annot.GetUseForegroundForTextColor();
// Compute the line opacity.
double lc[4];
lc[3] = double(lineColor.Alpha()) / 255.;
// Set the line color using the foreground color or the line color.
if(useForegroundForLineColor)
{
// Get the foreground color.
double fgColor[3];
mediator.GetForegroundColor(fgColor);
lineActor->GetProperty()->SetColor(fgColor[0], fgColor[1], fgColor[2]);
}
else
{
// Compute the line color as double.
lc[0] = double(lineColor.Red()) / 255.;
lc[1] = double(lineColor.Green()) / 255.;
lc[2] = double(lineColor.Blue()) / 255.;
lineActor->GetProperty()->SetColor(lc[0], lc[1], lc[2]);
}
lineActor->GetProperty()->SetOpacity(double(lc[3]));
}
//
// Set the object's visibility.
//
if(currentOptions.GetVisible() != annot.GetVisible())
{
SetVisible(annot.GetVisible());
if(annot.GetVisible())
AddToRenderer();
else
RemoveFromRenderer();
}
}
// ****************************************************************************
// Method: avtLine3DColleague::GetOptions
//
// Purpose:
// This method stores the attributes in an object that can
// be passed back to the client.
//
// Arguments:
// annot : The AnnotationObject to populate.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::GetOptions(AnnotationObject &annot)
{
annot.SetObjectType(AnnotationObject::Line3D);
annot.SetVisible(GetVisible());
annot.SetActive(GetActive());
annot.SetPosition(lineSource->GetPoint1());
annot.SetPosition2(lineSource->GetPoint2());
annot.SetColor1(lineColor);
annot.SetUseForegroundForTextColor(useForegroundForLineColor);
annot.SetIntAttribute1(lineActor->GetProperty()->GetLineWidth()-1);
annot.SetIntAttribute2(LineStyle2Int(StipplePattern2LineStyle(
lineActor->GetProperty()->GetLineStipplePattern())));
}
// ****************************************************************************
// Method: avtLine3DColleague::HasPlots
//
// Purpose:
// This method is called when the vis window gets some plots. We use this
// signal to add the lineActor to the renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::HasPlots(void)
{
AddToRenderer();
}
// ****************************************************************************
// Method: avtLine3DColleague::NoPlots
//
// Purpose:
// This method is called when the vis window has no plots. We use this signal
// to remove the lineActor from the renderer.
//
// Programmer: Kathleen Biagas
// Creation: July 13, 2015
//
// Modifications:
//
// ****************************************************************************
void
avtLine3DColleague::NoPlots(void)
{
RemoveFromRenderer();
}
// ****************************************************************************
// Method: avtLine3DColleague::SetForegroundColor