/*========================================================================= * * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ #ifndef itkBoxSpatialObject_hxx #define itkBoxSpatialObject_hxx #include "itkNumericTraits.h" namespace itk { template BoxSpatialObject::BoxSpatialObject() { this->SetTypeName("BoxSpatialObject"); this->Clear(); this->Update(); } template void BoxSpatialObject::Clear() { Superclass::Clear(); m_SizeInObjectSpace.Fill(1); m_PositionInObjectSpace.Fill(0); this->Modified(); } template bool BoxSpatialObject::IsInsideInObjectSpace(const PointType & point) const { itkDebugMacro("Checking the point [" << point << "] is in the box"); return this->GetMyBoundingBoxInObjectSpace()->IsInside(point); } template void BoxSpatialObject::ComputeMyBoundingBox() { itkDebugMacro("Computing BoxSpatialObject bounding box"); PointType pnt1; PointType pnt2; for (unsigned int i = 0; i < TDimension; ++i) { pnt1[i] = m_PositionInObjectSpace[i]; pnt2[i] = m_PositionInObjectSpace[i] + m_SizeInObjectSpace[i]; } this->GetModifiableMyBoundingBoxInObjectSpace()->SetMinimum(pnt1); this->GetModifiableMyBoundingBoxInObjectSpace()->SetMaximum(pnt1); this->GetModifiableMyBoundingBoxInObjectSpace()->ConsiderPoint(pnt2); this->GetModifiableMyBoundingBoxInObjectSpace()->ComputeBoundingBox(); } template typename LightObject::Pointer BoxSpatialObject::InternalClone() const { // Default implementation just copies the parameters from // this to new transform. typename LightObject::Pointer loPtr = Superclass::InternalClone(); typename Self::Pointer rval = dynamic_cast(loPtr.GetPointer()); if (rval.IsNull()) { itkExceptionMacro("downcast to type " << this->GetNameOfClass() << " failed."); } rval->SetSizeInObjectSpace(this->GetSizeInObjectSpace()); rval->SetPositionInObjectSpace(this->GetPositionInObjectSpace()); return loPtr; } template void BoxSpatialObject::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); os << indent << "SizeInObjectSpace: " << static_cast::PrintType>(m_SizeInObjectSpace) << std::endl; os << indent << "PositionInObjectSpace: " << static_cast::PrintType>(m_PositionInObjectSpace) << std::endl; } } // end namespace itk #endif