// ****************************************************************************
//
//  $Id: cisLine3D-inl.h,v 1.1.1.1 2001/09/27 20:12:22 anton Exp $
//
//  Description:
//		Inline methods for CISLine3D.hpp
//
//  Usage:
//		Included only by CISLine3D.hpp
//
//  See Also:
//		CISLine3D.hpp
//
//  Author(s):	Andrew Bzostek
//  Created on: ?/?/?
//
//
//              Developed by the Engineering Research Center for
//          Computer-Integrated Surgical Systems & Technology (CISST)
//
//               Copyright(c) 2001, The Johns Hopkins University
//                          All Rights Reserved.
//
//  Experimental Software - Not certified for clinical use.
//  For use only by CISST sponsored research projects.  For use outside of
//  CISST, please contact Dr. Russell Taylor, CISST Director, at rht@cs.jhu.edu
//  or Dr. Gabor Fichtinger, CISST Engineering Director, at gabor@cs.jhu.edu.
//  
// ****************************************************************************


#ifndef _cisLine3D_inl_h
#error "include of cisLine3D-inl.h is not allowed, include cisLine3D.h instead"
#endif

#if cisLine3D_mutable
inline
cisLine3D::cisLine3D()
  : Point(0.0, 0.0, 0.0), Dir(0.0, 0.0, 0.0)
{}
#endif

inline
cisLine3D::cisLine3D(const GlobalPointType & pt, const GlobalDirectionType & dir)
{
	this->Set(pt, dir);
}


inline
const cisLine3D::LocalPointType & cisLine3D::GetPoint() const
{
	return Point;
}


inline
const cisLine3D::LocalDirectionType & cisLine3D::GetDirection() const
{
	return Dir;
}


inline
cisLine3D::LocalPointType cisLine3D::EvalAt(ParametrizationType param) const
{
  LocalPointType retVal(GetPoint() + param * GetDirection());
  return retVal;
}


inline
cisLine3D::ParametrizationType cisLine3D::ProjectPointLocal(const GlobalPointType & pt) const
{
	cisVec3 diff(pt - GetPoint());
	cisScalar projectionLength = diff * GetDirection();
	return projectionLength;
}

inline
cisLine3D::GlobalPointType cisLine3D::ProjectPoint(const GlobalPointType & pt) const
{
	cisScalar projectionLength = ProjectPointLocal(pt);
	GlobalPointType result(GetPoint() + projectionLength * GetDirection());
	return result;
}


inline
cisScalar cisLine3D::DistanceSquareToPoint(const GlobalPointType & pt) const
{
	cisVec3 diff(pt - GetPoint());
	cisScalar projectionLength = diff * GetDirection();
	cisScalar distanceSquare = diff.LengthSquare() - (projectionLength * projectionLength);
	return distanceSquare;
}

inline
cisScalar cisLine3D::DistanceToPoint(const GlobalPointType & pt) const
{
	return sqrt(DistanceSquareToPoint(pt));
}


inline
bool cisLine3D::IsMember(const GlobalPointType & pt, cisScalar tolerance) const
{
	return (DistanceToPoint(pt) <= fabs(tolerance));
}

inline
cisLine3D::AngleType cisLine3D::AngleWithVector(const GlobalDirectionType & v) const
{
	cisVec3 vDir(v.Normalize());

	cisScalar prod = Dir * vDir;

	return acos(prod);
}


inline
cisLine3D::AngleType cisLine3D::AngleWithLine(const SelfType & other) const
{
	cisScalar prod = GetDirection() * other.GetDirection();
	return acos(prod);
}


inline
bool cisLine3D::IsParallelTo(const SelfType & other, cisScalar tolerance) const
{
	cisScalar prod = GetDirection() * other.GetDirection();

	cisScalar diff = fabs(1 - prod);

	return (diff <= fabs(tolerance));
}


inline
cisBool cisLine3D::operator == (const cisLine3D& L2) const
{
  return ((GetPoint() == L2.GetPoint()) && (GetDirection() == L2.GetDirection()));
}


inline
cisBool cisLine3D::operator != (const cisLine3D& L2) const
{
  return ((GetPoint() != L2.GetPoint()) || (GetDirection() != L2.GetDirection()));
}



// ****************************************************************************
//                              Change History
// ****************************************************************************
//
//  $Log: cisLine3D-inl.h,v $
//  Revision 1.1.1.1  2001/09/27 20:12:22  anton
//  Creation of new repository for CIS 2.
//
//
//  Older:
//
//  Revision 1.1  2001/03/26 19:32:05  anton
//  Import of GeomObj within CIS from Andy Bzostek code with some formating and cleaning.  Add some -inl.hpp files.
//
//
// ****************************************************************************


