File: pba.cpp

package info (click to toggle)
colmap 3.5-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 20,564 kB
  • sloc: ansic: 170,595; cpp: 95,339; python: 2,335; makefile: 183; sh: 51
file content (134 lines) | stat: -rwxr-xr-x 3,894 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
////////////////////////////////////////////////////////////////////////////
//  File:           pba.cpp
//  Author:         Changchang Wu
//  Description :   implementation of ParallelBA, which is a wrapper around
//                  the GPU-based and CPU-based implementations
//
//  Copyright (c) 2011  Changchang Wu (ccwu@cs.washington.edu)
//    and the University of Washington at Seattle
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation; either
//  Version 3 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  General Public License for more details.
//
////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <new>
#include "pba.h"
#include "SparseBundleCU.h"
#include "SparseBundleCPU.h"

namespace pba {

ParallelBA::ParallelBA(DeviceT device, const int num_threads) {
  // The wrapper intends to provide different implementations.

  if (device >= PBA_CUDA_DEVICE_DEFAULT)
#ifndef PBA_NO_GPU
  {
    SparseBundleCU* cuba = new SparseBundleCU(device - PBA_CUDA_DEVICE0);
    if (cuba->GetMemCapacity() > 0) {
      _optimizer = cuba;
    } else {
      device = PBA_CPU_FLOAT;
      _optimizer = NewSparseBundleCPU(false, num_threads);
      delete cuba;
    }
  } else
#else
    device = PBA_CPU_FLOAT;
#endif
      if (device == PBA_CPU_FLOAT)
    _optimizer = NewSparseBundleCPU(false, num_threads);
  else if (device == PBA_CPU_DOUBLE)
    _optimizer = NewSparseBundleCPU(true, num_threads);
  else
    _optimizer = NULL;
}

ParallelBA::~ParallelBA() {
  if (_optimizer) delete _optimizer;
}

void ParallelBA::ParseParam(int narg, char** argv) {
  _optimizer->ParseParam(narg, argv);
}

ConfigBA* ParallelBA::GetInternalConfig() {
  if (_optimizer)
    return _optimizer->GetInternalConfig();
  else
    return NULL;
}

void ParallelBA::SetFixedIntrinsics(bool fixed) {
  _optimizer->SetFixedIntrinsics(fixed);
}
void ParallelBA::EnableRadialDistortion(DistortionT enabled) {
  _optimizer->EnableRadialDistortion(enabled);
}
void ParallelBA::SetNextTimeBudget(int seconds) {
  _optimizer->SetNextTimeBudget(seconds);
}

void ParallelBA::SetNextBundleMode(BundleModeT mode) {
  _optimizer->SetNextBundleMode(mode);
}

void ParallelBA::SetCameraData(size_t ncam, CameraT* cams) {
  _optimizer->SetCameraData(ncam, cams);
}

void ParallelBA::SetPointData(size_t npoint, Point3D* pts) {
  _optimizer->SetPointData(npoint, pts);
}

void ParallelBA::SetProjection(size_t nproj, const Point2D* imgpts,
                               const int* point_idx, const int* cam_idx) {
  _optimizer->SetProjection(nproj, imgpts, point_idx, cam_idx);
}
int ParallelBA::RunBundleAdjustment() {
  return _optimizer->RunBundleAdjustment();
}

float ParallelBA::GetMeanSquaredError() {
  return _optimizer->GetMeanSquaredError();
}

int ParallelBA::GetCurrentIteration() {
  return _optimizer->GetCurrentIteration();
}
void ParallelBA::AbortBundleAdjustment() {
  return _optimizer->AbortBundleAdjustment();
}

void ParallelBA::ReserveStorage(size_t ncam, size_t npt, size_t nproj) {
  if (_optimizer) _optimizer->ReserveStorage(ncam, npt, nproj);
}

void ParallelBA::SetFocalMask(const int* fmask, float weight) {
  if (_optimizer && weight > 0) _optimizer->SetFocalMask(fmask, weight);
}

void* ParallelBA::operator new(size_t size) {
  void* p = malloc(size);
  if (p == 0) {
    const std::bad_alloc ba;
    throw ba;
  }
  return p;
}

ParallelBA* NewParallelBA(ParallelBA::DeviceT device) {
  return new ParallelBA(device);
}

int ParallelBA_GetVersion() { return 105; }

}  // namespace pba