-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from dcoeurjo/regularization
Regularization
- Loading branch information
Showing
13 changed files
with
1,334 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#pragma once | ||
|
||
#include <DGtal/base/Common.h> | ||
#include <DGtal/math/linalg/EigenSupport.h> | ||
|
||
struct RoundedCubeShape | ||
{ | ||
typedef DGtal::Z3i::Point Point; | ||
typedef Eigen::Vector3d Vector; | ||
typedef Eigen::Matrix3d Matrix; | ||
|
||
RoundedCubeShape(const Matrix& transform_, const double& size_, const double& radius_) : transform(transform_), size(size_), radius(radius_) | ||
{ | ||
ASSERT( radius < size ); | ||
} | ||
|
||
bool operator()(const Point& point) const | ||
{ | ||
const Vector vector_(point[0], point[1], point[2]); | ||
Vector vector = transform*vector_; | ||
vector = vector.cwiseAbs(); | ||
if (vector.maxCoeff() <= size-radius) return true; | ||
Vector projected = vector; | ||
for (int kk=0; kk<projected.size(); kk++) | ||
if (projected[kk] > size-radius) | ||
projected[kk] = size-radius; | ||
return (vector-projected).norm() <= radius; | ||
} | ||
|
||
Matrix transform; | ||
double size; | ||
double radius; | ||
}; | ||
|
||
struct TorusShape | ||
{ | ||
typedef DGtal::Z3i::Point Point; | ||
typedef Eigen::Vector3d Vector; | ||
typedef Eigen::Matrix3d Matrix; | ||
|
||
TorusShape(const Matrix& transform_, const double& radius_large_, const double& radius_small_) : transform(transform_), radius_large(radius_large_), radius_small(radius_small_) | ||
{ | ||
ASSERT( radius_small < radius_large ); | ||
} | ||
|
||
bool operator()(const Point& point) const | ||
{ | ||
const Vector vector_(point[0], point[1], point[2]); | ||
const Vector vector = transform*vector_; | ||
Vector projected = vector; | ||
projected[1] = 0; | ||
if (projected.norm() == 0) return false; | ||
projected *= radius_large/projected.norm(); | ||
return (vector-projected).norm() <= radius_small; | ||
} | ||
|
||
Matrix transform; | ||
double radius_large; | ||
double radius_small; | ||
}; | ||
|
||
struct SphereShape | ||
{ | ||
typedef DGtal::Z3i::Point Point; | ||
typedef DGtal::Z3i::RealPoint RealPoint; | ||
|
||
SphereShape(const double& radius_, const RealPoint& center_) : radius(radius_), center(center_) | ||
{ | ||
} | ||
|
||
bool operator()(const Point& point) const | ||
{ | ||
return (point-center).norm() <= radius; | ||
} | ||
|
||
double radius; | ||
RealPoint center; | ||
}; | ||
|
||
struct CapsuleShape | ||
{ | ||
typedef DGtal::Z3i::Point Point; | ||
typedef DGtal::Z3i::RealPoint RealPoint; | ||
|
||
CapsuleShape(const double& radius_, const double& length_, const RealPoint& direction_) : radius(radius_), length(length_), direction(direction_) | ||
{ | ||
if (direction.norm() > 0) direction /= direction.norm(); | ||
} | ||
|
||
bool operator()(const Point& point) const | ||
{ | ||
double alpha = direction.dot(point); | ||
if (alpha > length/2) alpha = length/2; | ||
if (alpha < -length/2) alpha = -length/2; | ||
return (point-alpha*direction).norm() <= radius; | ||
} | ||
|
||
double radius; | ||
double length; | ||
RealPoint direction; | ||
}; | ||
|
||
template <typename ImageType> | ||
struct ImageShape | ||
{ | ||
typedef typename ImageType::Point Point; | ||
typedef Eigen::Vector3d Vector; | ||
typedef Eigen::Matrix3d Matrix; | ||
|
||
ImageShape(const ImageType* image_, const Point& shift_) : image(image_), shift(shift_) | ||
{ | ||
ASSERT( image ); | ||
} | ||
|
||
bool operator()(const Point& point_) const | ||
{ | ||
const Point point = point_+shift; | ||
if (!image->domain().isInside(point)) return false; | ||
return (*image)(point) > 0; | ||
} | ||
|
||
const ImageType* image; | ||
Point shift; | ||
}; | ||
|
||
struct PlaneShape | ||
{ | ||
typedef DGtal::Z3i::Point Point; | ||
typedef DGtal::Z3i::RealPoint RealPoint; | ||
|
||
PlaneShape(const RealPoint& normal_) : normal(normal_) | ||
{ | ||
} | ||
|
||
bool operator()(const Point& point) const | ||
{ | ||
return normal.dot(point) <= 0; | ||
} | ||
|
||
RealPoint normal; | ||
}; |
Oops, something went wrong.