Skip to content

Commit

Permalink
Renamed isUnknown parameter in C++ wrapper class OptImage to usesOptF…
Browse files Browse the repository at this point in the history
…loat
  • Loading branch information
Mx7f committed Aug 8, 2018
1 parent c7da3fb commit c015849
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ See the [roadmap](https://github.com/niessner/Opt/blob/master/ROADMAP.md) for ne

## [Unreleased]

### Changed
- Renamed isUnknown parameter in C++ wrapper class OptImage to usesOptFloat
- Removed internal Opt compiler cruft.

### Fixed
- Small robustness changes for compilers. (mihaibujanca)


## [0.2.2] - 2017-11-29
### Added
- Higher verbosity levels, along with documentation
Expand Down
4 changes: 2 additions & 2 deletions examples/shape_from_shading/src/SFSSolverInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
static std::shared_ptr<OptImage> createWrapperOptImage(std::shared_ptr<SimpleBuffer> simpleBuffer) {
std::vector<unsigned int> dims = { (unsigned int)simpleBuffer->width(), (unsigned int)simpleBuffer->height() };
OptImage::Type t = (simpleBuffer->type() == SimpleBuffer::DataType::FLOAT) ? OptImage::Type::FLOAT : OptImage::Type::UCHAR;
bool isUnknown = (t == OptImage::Type::FLOAT);
return std::shared_ptr<OptImage>(new OptImage(dims, simpleBuffer->data(), t, 1, OptImage::Location::GPU, isUnknown, false));
bool usesOptFloat = (t == OptImage::Type::FLOAT);
return std::shared_ptr<OptImage>(new OptImage(dims, simpleBuffer->data(), t, 1, OptImage::Location::GPU, usesOptFloat, false));
}

struct SFSSolverInput {
Expand Down
2 changes: 1 addition & 1 deletion examples/shared/NamedParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NamedParameters {
std::vector<Parameter> unknownParameters() const {
std::vector<Parameter> params;
for (auto p : m_parameters) {
if (p.im && p.im->isUnknown()) {
if (p.im && p.im->usesOptFloat()) {
params.push_back(p);
}
}
Expand Down
18 changes: 9 additions & 9 deletions examples/shared/OptImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class OptImage {
public:
enum Type { FLOAT, DOUBLE, UCHAR, INT };
enum Location { CPU, GPU };
OptImage(std::vector<unsigned int> dims, void* data, Type type, unsigned int channelCount, Location location, bool isUnknown = false, bool ownsData = false) :
m_dims(dims), m_data(data), m_type(type), m_channelCount(channelCount), m_location(location), m_isUnknown(isUnknown), m_ownsData(ownsData) {
OptImage(std::vector<unsigned int> dims, void* data, Type type, unsigned int channelCount, Location location, bool usesOptFloat = false, bool ownsData = false) :
m_dims(dims), m_data(data), m_type(type), m_channelCount(channelCount), m_location(location), m_usesOptFloat(usesOptFloat), m_ownsData(ownsData) {
}

~OptImage() {
Expand All @@ -33,7 +33,7 @@ class OptImage {
Location location() const { return m_location; }
Type type() const { return m_type; }
std::vector<unsigned int> dims() const { return m_dims; }
bool isUnknown() const { return m_isUnknown; }
bool usesOptFloat() const { return m_usesOptFloat; }

size_t dataSize() const { return totalElementsFromDims(m_dims) * OptImage::typeSize(m_type) * m_channelCount; }

Expand Down Expand Up @@ -86,21 +86,21 @@ class OptImage {
std::vector<unsigned int> m_dims;
unsigned int m_channelCount = 0;
void* m_data = nullptr;
bool m_isUnknown = false;
bool m_usesOptFloat = false;
Type m_type = Type::FLOAT;
Location m_location = Location::CPU;
};


static std::shared_ptr<OptImage> createEmptyOptImage(std::vector<unsigned int> dims, OptImage::Type type, unsigned int channelCount, OptImage::Location location, bool isUnknown) {
static std::shared_ptr<OptImage> createEmptyOptImage(std::vector<unsigned int> dims, OptImage::Type type, unsigned int channelCount, OptImage::Location location, bool usesOptFloat) {
void* data;
size_t size = totalElementsFromDims(dims) * OptImage::typeSize(type) * channelCount;
if (location == OptImage::Location::CPU) {
data = malloc(size);
} else {
cudaSafeCall(cudaMalloc(&data, size));
}
return std::shared_ptr<OptImage>(new OptImage(dims, data, type, channelCount, location, isUnknown, true));
return std::shared_ptr<OptImage>(new OptImage(dims, data, type, channelCount, location, usesOptFloat, true));
}

static void copyImage(const std::shared_ptr<OptImage>& dst, const std::shared_ptr<OptImage>& src) {
Expand All @@ -111,15 +111,15 @@ static void copyImage(const std::shared_ptr<OptImage>& dst, const std::shared_pt
}

static std::shared_ptr<OptImage> copyImageTo(const std::shared_ptr<OptImage>& original, OptImage::Location location) {
std::shared_ptr<OptImage> newIm = createEmptyOptImage(original->dims(), original->type(), original->channelCount(), location, original->isUnknown());
std::shared_ptr<OptImage> newIm = createEmptyOptImage(original->dims(), original->type(), original->channelCount(), location, original->usesOptFloat());
copyImage(newIm, original);
return newIm;
}

// Only CPU->CPU
static std::shared_ptr<OptImage> getDoubleImageFromFloatImage(const std::shared_ptr<OptImage> floatImage) {
assert(floatImage->location() == OptImage::Location::CPU && floatImage->type() == OptImage::Type::FLOAT);
std::shared_ptr<OptImage> newIm = createEmptyOptImage(floatImage->dims(), OptImage::Type::DOUBLE, floatImage->channelCount(), floatImage->location(), floatImage->isUnknown());
std::shared_ptr<OptImage> newIm = createEmptyOptImage(floatImage->dims(), OptImage::Type::DOUBLE, floatImage->channelCount(), floatImage->location(), floatImage->usesOptFloat());
float* fPtr = (float*)floatImage->data();
double* dPtr = (double*)newIm->data();
for (size_t i = 0; i < totalElementsFromDims(floatImage->dims()) * floatImage->channelCount(); ++i) {
Expand All @@ -131,7 +131,7 @@ static std::shared_ptr<OptImage> getDoubleImageFromFloatImage(const std::shared_
// Only CPU->CPU
static std::shared_ptr<OptImage> getFloatImageFromDoubleImage(const std::shared_ptr<OptImage> doubleImage) {
assert(doubleImage->location() == OptImage::Location::CPU && doubleImage->type() == OptImage::Type::DOUBLE);
std::shared_ptr<OptImage> newIm = createEmptyOptImage(doubleImage->dims(), OptImage::Type::FLOAT, doubleImage->channelCount(), doubleImage->location(), doubleImage->isUnknown());
std::shared_ptr<OptImage> newIm = createEmptyOptImage(doubleImage->dims(), OptImage::Type::FLOAT, doubleImage->channelCount(), doubleImage->location(), doubleImage->usesOptFloat());
double* dPtr = (double*)doubleImage->data();
float* fPtr = (float*)newIm->data();
for (size_t i = 0; i < totalElementsFromDims(doubleImage->dims()) * doubleImage->channelCount(); ++i) {
Expand Down

0 comments on commit c015849

Please sign in to comment.