├── .dockerignore ├── .gitignore ├── Dockerfile ├── README.md ├── checkpoints └── get_pretrained.sh ├── enter_docker.sh ├── envars.sh ├── example └── get_example.sh ├── imgs ├── simplecam_recordview.png └── simplecamcreator.png ├── inference.py ├── model ├── SparseConvNet.py ├── __init__.py ├── __pycache__ │ ├── SparseConvNet.cpython-37.pyc │ ├── __init__.cpython-37.pyc │ ├── cascademodel.cpython-37.pyc │ ├── simplenet.cpython-37.pyc │ ├── unet.cpython-37.pyc │ ├── unetOCR.cpython-37.pyc │ ├── unet_edg.cpython-37.pyc │ ├── unet_nconv.cpython-37.pyc │ ├── unet_nobn.cpython-37.pyc │ ├── unet_partialconv.cpython-37.pyc │ └── vvvnet.cpython-37.pyc ├── cascademodel.py ├── model_parts │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── nconv.cpython-37.pyc │ │ └── partialconv2d.cpython-37.pyc │ ├── nconv.py │ └── partialconv2d.py ├── simplenet.py ├── unet.py ├── unetOCR.py ├── unet_edg.py ├── unet_nconv.py ├── unet_nobn.py ├── unet_partialconv.py └── vvvnet.py ├── setup_tools.sh ├── tools ├── build_openmvs.sh ├── build_vvmesh.sh └── vvmesh_src │ ├── .clang-format │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── apps │ ├── CMakeLists.txt │ ├── bundle_packing │ │ ├── CLOUD_BUNDLE_plugin.cpp │ │ ├── CLOUD_BUNDLE_plugin.h │ │ ├── CMakeLists.txt │ │ └── bundle_packing_main.cpp │ ├── glrender │ │ ├── CMakeLists.txt │ │ ├── GLRENDER_plugin.cpp │ │ ├── GLRENDER_plugin.h │ │ ├── env_setup.h │ │ ├── glrender_main.cpp │ │ └── nanoflann.hpp │ ├── simplecamcreator │ │ ├── CMakeLists.txt │ │ └── o3d_vvcreator.py │ ├── visibility_filter │ │ ├── CMakeLists.txt │ │ ├── GTFILTER_plugin.cpp │ │ ├── GTFILTER_plugin.h │ │ ├── RAYGTFILTER_plugin.cpp │ │ ├── RAYGTFILTER_plugin.h │ │ └── env_setup.h │ ├── visibility_network │ │ ├── CMakeLists.txt │ │ ├── NETWORKVISIBILITY_plugin.cpp │ │ ├── NETWORKVISIBILITY_plugin.h │ │ ├── O3DHPRVISIBILITY_plugin.cpp │ │ ├── O3DHPRVISIBILITY_plugin.h │ │ ├── debug │ │ │ ├── CMakeLists.txt │ │ │ ├── example_call.cpp │ │ │ ├── example_call2.cpp │ │ │ └── run_networkplugin.cpp │ │ ├── hpr_predict.py │ │ ├── json2pydict.cpp │ │ ├── json2pydict.h │ │ └── network_predict.py │ └── vvtool │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── pybind11 │ │ └── vvtool_pybind11.cpp │ ├── cmake │ ├── BuildExternalDeps.cmake │ ├── PrintProps.cmake │ └── conan │ │ ├── openvolumemesh │ │ └── conanfile.py │ │ ├── pcl │ │ ├── README.md │ │ ├── conanfile.py │ │ └── select_compute_arch.cmake │ │ ├── qhullcpp │ │ └── conanfile.py │ │ └── vtk │ │ ├── README.md │ │ ├── conanfile.py │ │ ├── vtknetcdf_snprintf.diff │ │ └── vtktiff_mangle.diff │ └── src │ ├── CMakeLists.txt │ ├── FBORender │ ├── CMakeLists.txt │ ├── FBORender.h │ ├── dllmacro.h │ ├── glsl │ │ ├── pointcloud.fs │ │ ├── pointcloud.vs │ │ ├── pointcloud_box.gs │ │ ├── pointcloud_diamond.gs │ │ ├── pointcloud_dot.gs │ │ ├── pointcloud_point.gs │ │ ├── rgbtrimesh.fs │ │ ├── rgbtrimesh.vs │ │ ├── texturedtrimesh.fs │ │ ├── texturedtrimesh.vs │ │ ├── trimesh.fs │ │ ├── trimesh.vs │ │ └── wwzb.cs │ ├── multidrawfbo.cpp │ ├── multidrawfbo.h │ ├── pybind11 │ │ ├── __init__.py │ │ ├── fborender_pybind11.cpp │ │ └── setup.py │ ├── reader.h │ ├── renderobjects.cpp │ ├── renderobjects.h │ ├── util.cpp │ └── util.h │ ├── MVArchive │ ├── ARInterface.cpp │ ├── ARInterface.h │ ├── ARInterface_impl.hpp │ ├── CMakeLists.txt │ ├── dllmacro.h │ ├── gzstream │ │ ├── COPYING.LIB │ │ ├── README │ │ ├── gzstream.h │ │ └── version │ ├── pybind11 │ │ ├── ARInteface_pybind11_types.cpp │ │ ├── ARInterface_pybind11.cpp │ │ ├── ARInterface_pybind11_scene.cpp │ │ ├── ARInterface_pybind11_scene.h │ │ ├── CMakeLists.txt │ │ └── setup.py │ └── zstdstream │ │ ├── LICENSE │ │ ├── circularbuffer.h │ │ ├── zstdstream.cpp │ │ └── zstdstream.h │ ├── OBJFile │ ├── CMakeLists.txt │ ├── obj.cpp │ ├── obj.h │ └── test │ │ ├── Tile_+000_+007_L17.mtl │ │ ├── Tile_+000_+007_L17_0.jpg │ │ └── test_OBJFile.cpp │ ├── Plugin │ ├── CMakeLists.txt │ ├── builtin_plugins.cpp │ ├── builtin_plugins.h │ ├── dllmacro.h │ ├── plugininterface.cpp │ ├── plugininterface.h │ ├── pluginmanager.cpp │ ├── pluginmanager.h │ ├── preprocess_json.cpp │ ├── preprocess_json.h │ └── test │ │ └── test_plugin.cpp │ ├── UtilProgressBar.h │ └── filesystem │ ├── LICENSE.txt │ ├── fwd.h │ ├── ghc │ ├── LICENSE │ ├── filesystem.hpp │ ├── fs_fwd.hpp │ ├── fs_impl.hpp │ ├── fs_std.hpp │ ├── fs_std_fwd.hpp │ └── fs_std_impl.hpp │ ├── glob │ ├── LICENSE │ └── glob.hpp │ ├── path.h │ └── resolver.h └── utils ├── __init__.py ├── __pycache__ ├── __init__.cpython-37.pyc ├── dataset_util.cpython-37.pyc ├── dice_loss.cpython-37.pyc └── visdataset.cpython-37.pyc ├── dataset_util.py ├── dice_loss.py ├── vis2mesh_makedata.py └── visdataset.py /.dockerignore: -------------------------------------------------------------------------------- 1 | example/ 2 | checkpoints/ 3 | imgs/ 4 | dataset/ 5 | ignore/ 6 | *.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tools/bin 2 | tools/include 3 | tools/lib 4 | tools/openMVS_build 5 | tools/vvmesh_build 6 | tools/vcglib 7 | evaluation/* 8 | trainer/* 9 | example/*.ply* 10 | ###### VVMESH ### 11 | /cmake-build-*/** 12 | *.pyc 13 | **/__pycache__/** 14 | *.obj 15 | *.mva 16 | .idea 17 | .dir-locals.el 18 | *.pth 19 | *.ovm 20 | **/build/* 21 | **/tmp/* 22 | *.so 23 | **/.eggs/* 24 | /testdata/* 25 | /cmake-build-*/ 26 | **/generated/* 27 | workspace.code-workspace 28 | .vscode/ 29 | /apps/wwzb_filter/test/ 30 | /apps/normalestimation/test/ 31 | cache.pk 32 | **/ignore/** 33 | .vs/ 34 | CMakeSettings.json 35 | /external/ 36 | /hunter_deps/ 37 | **.ply_WORK/** -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM pytorch/pytorch:1.9.0-cuda10.2-cudnn7-runtime 2 | LABEL maintainer="Shaun Song " 3 | 4 | ENV DEBIAN_FRONTEND=noninteractive 5 | ENV NVIDIA_DRIVER_CAPABILITIES=all 6 | ENV MESA_GL_VERSION_OVERRIDE=4.5 7 | ENV MESA_GLSL_VERSION_OVERRIDE=450 8 | 9 | COPY . /workspace 10 | RUN cd /workspace && bash setup_tools.sh 11 | 12 | ENV main_path="/workspace" 13 | ENV PYTHON_LIBDIR="/opt/conda/lib" 14 | ENV PATH="$main_path/tools/bin/OpenMVS:$main_path/tools/bin:$PATH" 15 | ENV LD_LIBRARY_PATH="$main_path/tools/lib/OpenMVS:$main_path/tools/lib:$PYTHON_LIBDIR:$LD_LIBRARY_PATH" 16 | ENV PYTHONPATH="$main:$main_path/tools/lib" -------------------------------------------------------------------------------- /checkpoints/get_pretrained.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd "$( dirname "${BASH_SOURCE[0]}" )" 3 | gdown --id 1cxWPWTJgMuUrbvnKp5hDmxzqCyNVV8Yd -------------------------------------------------------------------------------- /enter_docker.sh: -------------------------------------------------------------------------------- 1 | xhost + 2 | name=vis2mesh 3 | # Run in interactive mode 4 | docker run -it \ 5 | --mount type=bind,source="$PWD/checkpoints",target=/workspace/checkpoints \ 6 | --mount type=bind,source="$PWD/example",target=/workspace/example \ 7 | --privileged \ 8 | -e NVIDIA_DRIVER_CAPABILITIES=all \ 9 | -e DISPLAY=unix$DISPLAY \ 10 | -v $XAUTH:/root/.Xauthority \ 11 | -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ 12 | --device=/dev/dri \ 13 | --gpus all $name 14 | 15 | cd /workspace 16 | inference.py example/example1.ply --cam cam0 17 | 18 | # Run with single shot call 19 | docker run \ 20 | --mount type=bind,source="$PWD/checkpoints",target=/workspace/checkpoints \ 21 | --mount type=bind,source="$PWD/example",target=/workspace/example \ 22 | --privileged \ 23 | -e NVIDIA_DRIVER_CAPABILITIES=all \ 24 | -e DISPLAY=unix$DISPLAY \ 25 | -v $XAUTH:/root/.Xauthority \ 26 | -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ 27 | --device=/dev/dri \ 28 | --gpus all $name \ 29 | /workspace/inference.py example/example1.ply --cam cam0 30 | 31 | 32 | -------------------------------------------------------------------------------- /envars.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export main_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 3 | export PYTHON_LIBDIR=`python -c 'from distutils import sysconfig;print(sysconfig.get_config_var("LIBDIR"))'` 4 | export PATH="$main_path/tools/bin/OpenMVS:$main_path/tools/bin:$PATH" 5 | export LD_LIBRARY_PATH="$main_path/tools/lib/OpenMVS:$main_path/tools/lib:$PYTHON_LIBDIR:$LD_LIBRARY_PATH" 6 | export PYTHONPATH="$main:$main_path/tools/lib" -------------------------------------------------------------------------------- /example/get_example.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd "$( dirname "${BASH_SOURCE[0]}" )" 3 | gdown --id 14Aw53hXitdJ0tIje2sKQnPNc22U5yZft 4 | tar zxvf example.tar.gz 5 | rm example.tar.gz -------------------------------------------------------------------------------- /imgs/simplecam_recordview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/imgs/simplecam_recordview.png -------------------------------------------------------------------------------- /imgs/simplecamcreator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/imgs/simplecamcreator.png -------------------------------------------------------------------------------- /model/SparseConvNet.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | 6 | class SparseConv(nn.Module): 7 | 8 | def __init__(self, 9 | in_channels, 10 | out_channels, 11 | kernel_size, 12 | active_fn): 13 | super().__init__() 14 | 15 | padding = kernel_size // 2 16 | 17 | self.conv = nn.Conv2d( 18 | in_channels, 19 | out_channels, 20 | kernel_size=kernel_size, 21 | padding=padding, 22 | bias=False) 23 | 24 | self.bias = nn.Parameter( 25 | torch.zeros(out_channels), 26 | requires_grad=True) 27 | 28 | self.sparsity = nn.Conv2d( 29 | in_channels, 30 | out_channels, 31 | kernel_size=kernel_size, 32 | padding=padding, 33 | bias=False) 34 | 35 | kernel = torch.FloatTensor(torch.ones([kernel_size, kernel_size])).unsqueeze(0).unsqueeze(0) 36 | 37 | self.sparsity.weight = nn.Parameter( 38 | data=kernel, 39 | requires_grad=False) 40 | self.active_fn = active_fn 41 | if self.active_fn: 42 | self.relu = nn.ReLU(inplace=True) 43 | 44 | self.max_pool = nn.MaxPool2d( 45 | kernel_size, 46 | stride=1, 47 | padding=padding) 48 | self.bn = nn.BatchNorm2d(out_channels) 49 | 50 | def forward(self, x, mask): 51 | x = x * mask 52 | x = self.conv(x) 53 | normalizer = 1 / (self.sparsity(mask) + 1e-8) 54 | x = x * normalizer + self.bias.unsqueeze(0).unsqueeze(2).unsqueeze(3) 55 | x = self.bn(x) 56 | if self.active_fn: 57 | x = self.relu(x) 58 | 59 | mask = self.max_pool(mask) 60 | 61 | return x, mask 62 | 63 | 64 | class SparseConvNet(nn.Module): 65 | 66 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 67 | super().__init__() 68 | assert (input_channels >= 2) 69 | self.n_channels = input_channels 70 | self.n_classes = num_classes 71 | self.return_conf = kwargs.get('return_conf', False) 72 | 73 | self.SparseLayer1 = SparseConv(input_channels - 1, 16, 11, active_fn=True) 74 | self.SparseLayer2 = SparseConv(16, 16, 7, active_fn=True) 75 | self.SparseLayer3 = SparseConv(16, 16, 5, active_fn=True) 76 | self.SparseLayer4 = SparseConv(16, 16, 3, active_fn=True) 77 | self.SparseLayer5 = SparseConv(16, 16, 3, active_fn=True) 78 | self.SparseLayer6 = SparseConv(16, num_classes, 1, active_fn=False) 79 | 80 | def forward(self, x): 81 | datach = [i for i in range(x.shape[1]) if i != 1] 82 | maskch = [1] 83 | 84 | x_data = x[:, datach, :, :] 85 | x_mask = x[:, maskch, :, :] 86 | 87 | x, x_conf = self.SparseLayer1(x_data, x_mask) 88 | x, x_conf = self.SparseLayer2(x, x_conf) 89 | x, x_conf = self.SparseLayer3(x, x_conf) 90 | x, x_conf = self.SparseLayer4(x, x_conf) 91 | x, x_conf = self.SparseLayer5(x, x_conf) 92 | x, x_conf = self.SparseLayer6(x, x_conf) 93 | 94 | if self.return_conf: 95 | return x, x_conf 96 | else: 97 | return x 98 | 99 | if __name__ == '__main__': 100 | from torchsummary import summary 101 | 102 | summary(SparseConvNet(input_channels=2), (2, 64, 64)) 103 | summary(SparseConvNet(input_channels=5), (5, 64, 64)) 104 | -------------------------------------------------------------------------------- /model/__init__.py: -------------------------------------------------------------------------------- 1 | from .simplenet import * 2 | from .unet import UNet, UNetEx, UNet2Tasks 3 | from .unet_nobn import UNetNOBN 4 | from .unet_edg import UNetEDG 5 | from .unet_nconv import NConvUNet 6 | from .unet_partialconv import PartialConvUNet,PartialConvUNetMT 7 | from .SparseConvNet import SparseConvNet 8 | from .cascademodel import CascadeNet 9 | from .unetOCR import UNetOCR 10 | from .vvvnet import VVVNet -------------------------------------------------------------------------------- /model/__pycache__/SparseConvNet.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/SparseConvNet.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/cascademodel.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/cascademodel.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/simplenet.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/simplenet.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unet.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unet.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unetOCR.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unetOCR.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unet_edg.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unet_edg.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unet_nconv.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unet_nconv.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unet_nobn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unet_nobn.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/unet_partialconv.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/unet_partialconv.cpython-37.pyc -------------------------------------------------------------------------------- /model/__pycache__/vvvnet.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/__pycache__/vvvnet.cpython-37.pyc -------------------------------------------------------------------------------- /model/cascademodel.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.functional as F 4 | from model import * 5 | 6 | class CascadeNet(nn.Module): 7 | def __init__(self, arch, trainable=[True,True,True], multitask = False): 8 | super().__init__() 9 | self.multitask = multitask 10 | assert(len(arch) == 3) 11 | self.net = nn.ModuleList() 12 | self.trainable = trainable 13 | for a in arch: 14 | try: 15 | _n = eval(a) 16 | # cmd = f'_n = {a}' 17 | # exec(cmd) 18 | # print(cmd) 19 | assert (_n is not None) 20 | self.net.append(_n) 21 | except Exception as e: 22 | raise RuntimeError(f'net architecture {a} init failed:\n {e}') 23 | 24 | assert (len(self.net) == 3) 25 | assert (len(self.trainable ) == 3) 26 | 27 | def forward(self, x): 28 | input_depth = x[:,0:1,:,:] 29 | input_mask = x[:,1:2,:,:] # second channel, the mask 30 | pred_vis = self.net[0](x) 31 | 32 | pred_bgmask = (torch.sigmoid(pred_vis) * input_mask > 0.5).float() 33 | x_clean = x.clone() 34 | x_clean = x_clean * (1-pred_bgmask).repeat(1,x.shape[1],1,1) 35 | pred_depth = self.net[1](x_clean) 36 | pred_depth = torch.sigmoid(pred_depth) 37 | 38 | depth_diff = (pred_depth - input_depth) * input_mask 39 | pred_finevis = self.net[2](torch.cat([x, depth_diff], dim=1)) 40 | 41 | if self.multitask: 42 | return pred_vis, pred_depth, pred_finevis 43 | else: 44 | return pred_finevis 45 | 46 | def train(self, mode=True): 47 | super().train(mode) 48 | for i in range(len(self.net)): 49 | if self.trainable[i]: 50 | self.net[i].train(mode) 51 | else: 52 | self.net[i].eval() 53 | 54 | def cvtCheckpoint3to1(arch,input,output): 55 | n = CascadeNet(arch) 56 | statedicts = torch.load(input) 57 | n.net[0].load_state_dict(statedicts['net0']) 58 | n.net[1].load_state_dict(statedicts['net1']) 59 | n.net[2].load_state_dict(statedicts['net2']) 60 | torch.save(n.state_dict(), output) 61 | return n 62 | 63 | if __name__ == '__main__': 64 | device = torch.device('cuda') 65 | arch = ['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'UNet(input_channels=3)'] 66 | 67 | # /home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadePPP_epoch30_raw.pth 68 | # /home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadePPU_epoch30_raw.pth 69 | # /home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadeUPP_epoch30_raw.pth 70 | # /home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadeUPU_epoch30_raw.pth 71 | # /home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadeUUU_epoch30_raw.pth 72 | old_weight = "/home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadePPU_epoch30_raw.pth" 73 | new_weight = "/home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadePPU_epoch30.pth" 74 | 75 | with torch.no_grad(): 76 | net = CascadeNet(arch).cuda() 77 | # net = cvtCheckpoint3to1(arch,old_weight,new_weight).to(device=device) 78 | 79 | import torchsummary 80 | torchsummary.summary(net,(2,256,256)) 81 | -------------------------------------------------------------------------------- /model/model_parts/__init__.py: -------------------------------------------------------------------------------- 1 | from .nconv import * 2 | from .partialconv2d import * -------------------------------------------------------------------------------- /model/model_parts/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/model_parts/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /model/model_parts/__pycache__/nconv.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/model_parts/__pycache__/nconv.cpython-37.pyc -------------------------------------------------------------------------------- /model/model_parts/__pycache__/partialconv2d.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/model/model_parts/__pycache__/partialconv2d.cpython-37.pyc -------------------------------------------------------------------------------- /model/model_parts/nconv.py: -------------------------------------------------------------------------------- 1 | ######################################## 2 | __author__ = "Abdelrahman Eldesokey" 3 | __license__ = "GNU GPLv3" 4 | __version__ = "0.1" 5 | __maintainer__ = "Abdelrahman Eldesokey" 6 | __email__ = "abdo.eldesokey@gmail.com" 7 | ######################################## 8 | 9 | import torch 10 | import torch.nn.functional as F 11 | from torch.nn.parameter import Parameter 12 | from torch.nn.modules.conv import _ConvNd 13 | import numpy as np 14 | from scipy.stats import poisson 15 | from scipy import signal 16 | 17 | # The proposed Normalized Convolution Layer 18 | class NConv2d(_ConvNd): 19 | def __init__(self, in_channels, out_channels, kernel_size, pos_fn='softplus', init_method='k', stride=1, padding=0, dilation=1, groups=1, bias=True): 20 | 21 | # Call _ConvNd constructor 22 | super(NConv2d, self).__init__(in_channels, out_channels, kernel_size, stride, (padding,padding), dilation, False, 0, groups, bias,'zeros') 23 | 24 | self.eps = 1e-20 25 | self.pos_fn = pos_fn 26 | self.init_method = init_method 27 | 28 | # Initialize weights and bias 29 | self.init_parameters() 30 | 31 | if self.pos_fn is not None : 32 | EnforcePos.apply(self, 'weight', pos_fn) 33 | 34 | 35 | 36 | def forward(self, data, conf): 37 | 38 | # Normalized Convolution 39 | denom = F.conv2d(conf, self.weight, None, self.stride, 40 | self.padding, self.dilation, self.groups) 41 | nomin = F.conv2d(data*conf, self.weight, None, self.stride, 42 | self.padding, self.dilation, self.groups) 43 | nconv = nomin / (denom+self.eps) 44 | 45 | 46 | # Add bias 47 | b = self.bias 48 | sz = b.size(0) 49 | b = b.view(1,sz,1,1) 50 | b = b.expand_as(nconv) 51 | nconv += b 52 | 53 | # Propagate confidence 54 | cout = denom 55 | sz = cout.size() 56 | cout = cout.view(sz[0], sz[1], -1) 57 | 58 | k = self.weight 59 | k_sz = k.size() 60 | k = k.view(k_sz[0], -1) 61 | s = torch.sum(k, dim=-1, keepdim=True) 62 | 63 | cout = cout / s 64 | cout = cout.view(sz) 65 | 66 | return nconv, cout 67 | 68 | 69 | def init_parameters(self): 70 | # Init weights 71 | if self.init_method == 'x': # Xavier 72 | torch.nn.init.xavier_uniform_(self.weight) 73 | elif self.init_method == 'k': # Kaiming 74 | torch.nn.init.kaiming_uniform_(self.weight) 75 | elif self.init_method == 'p': # Poisson 76 | mu=self.kernel_size[0]/2 77 | dist = poisson(mu) 78 | x = np.arange(0, self.kernel_size[0]) 79 | y = np.expand_dims(dist.pmf(x),1) 80 | w = signal.convolve2d(y, y.transpose(), 'full') 81 | w = torch.Tensor(w).type_as(self.weight) 82 | w = torch.unsqueeze(w,0) 83 | w = torch.unsqueeze(w,1) 84 | w = w.repeat(self.out_channels, 1, 1, 1) 85 | w = w.repeat(1, self.in_channels, 1, 1) 86 | self.weight.data = w + torch.rand(w.shape) 87 | 88 | # Init bias 89 | self.bias = torch.nn.Parameter(torch.zeros(self.out_channels)+0.01) 90 | 91 | 92 | # Non-negativity enforcement class 93 | class EnforcePos(object): 94 | def __init__(self, pos_fn, name): 95 | self.name = name 96 | self.pos_fn = pos_fn 97 | 98 | 99 | @staticmethod 100 | def apply(module, name, pos_fn): 101 | fn = EnforcePos(pos_fn, name) 102 | 103 | module.register_forward_pre_hook(fn) 104 | 105 | return fn 106 | 107 | def __call__(self, module, inputs): 108 | if module.training: 109 | weight = getattr(module, self.name) 110 | weight.data = self._pos(weight).data 111 | else: 112 | pass 113 | 114 | def _pos(self, p): 115 | pos_fn = self.pos_fn.lower() 116 | if pos_fn == 'softmax': 117 | p_sz = p.size() 118 | p = p.view(p_sz[0],p_sz[1], -1) 119 | p = F.softmax(p, -1) 120 | return p.view(p_sz) 121 | elif pos_fn == 'exp': 122 | return torch.exp(p) 123 | elif pos_fn == 'softplus': 124 | return F.softplus(p, beta=10) 125 | elif pos_fn == 'sigmoid': 126 | return F.sigmoid(p) 127 | else: 128 | print('Undefined positive function!') 129 | return 130 | 131 | -------------------------------------------------------------------------------- /model/model_parts/partialconv2d.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # BSD 3-Clause License 3 | # 4 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. 5 | # 6 | # Author & Contact: Guilin Liu (guilinl@nvidia.com) 7 | ############################################################################### 8 | 9 | import torch 10 | import torch.nn.functional as F 11 | from torch import nn, cuda 12 | from torch.autograd import Variable 13 | 14 | class PartialConv2d(nn.Conv2d): 15 | def __init__(self, *args, **kwargs): 16 | 17 | # whether the mask is multi-channel or not 18 | if 'multi_channel' in kwargs: 19 | self.multi_channel = kwargs['multi_channel'] 20 | kwargs.pop('multi_channel') 21 | else: 22 | self.multi_channel = False 23 | 24 | if 'return_mask' in kwargs: 25 | self.return_mask = kwargs['return_mask'] 26 | kwargs.pop('return_mask') 27 | else: 28 | self.return_mask = False 29 | 30 | super(PartialConv2d, self).__init__(*args, **kwargs) 31 | 32 | if self.multi_channel: 33 | self.weight_maskUpdater = torch.ones(self.out_channels, self.in_channels, self.kernel_size[0], self.kernel_size[1]) 34 | else: 35 | self.weight_maskUpdater = torch.ones(1, 1, self.kernel_size[0], self.kernel_size[1]) 36 | 37 | self.slide_winsize = self.weight_maskUpdater.shape[1] * self.weight_maskUpdater.shape[2] * self.weight_maskUpdater.shape[3] 38 | 39 | self.last_size = (None, None, None, None) 40 | self.update_mask = None 41 | self.mask_ratio = None 42 | 43 | def forward(self, input, mask_in=None): 44 | assert len(input.shape) == 4 45 | if mask_in is not None or self.last_size != tuple(input.shape): 46 | self.last_size = tuple(input.shape) 47 | 48 | with torch.no_grad(): 49 | if self.weight_maskUpdater.type() != input.type(): 50 | self.weight_maskUpdater = self.weight_maskUpdater.to(input) 51 | 52 | if mask_in is None: 53 | # if mask is not provided, create a mask 54 | if self.multi_channel: 55 | mask = torch.ones(input.data.shape[0], input.data.shape[1], input.data.shape[2], input.data.shape[3]).to(input) 56 | else: 57 | mask = torch.ones(1, 1, input.data.shape[2], input.data.shape[3]).to(input) 58 | else: 59 | mask = mask_in 60 | 61 | self.update_mask = F.conv2d(mask, self.weight_maskUpdater, bias=None, stride=self.stride, padding=self.padding, dilation=self.dilation, groups=1) 62 | 63 | # for mixed precision training, change 1e-8 to 1e-6 64 | self.mask_ratio = self.slide_winsize/(self.update_mask + 1e-8) 65 | # self.mask_ratio = torch.max(self.update_mask)/(self.update_mask + 1e-8) 66 | self.update_mask = torch.clamp(self.update_mask, 0, 1) 67 | self.mask_ratio = torch.mul(self.mask_ratio, self.update_mask) 68 | 69 | 70 | raw_out = super(PartialConv2d, self).forward(torch.mul(input, mask) if mask_in is not None else input) 71 | 72 | if self.bias is not None: 73 | bias_view = self.bias.view(1, self.out_channels, 1, 1) 74 | output = torch.mul(raw_out - bias_view, self.mask_ratio) + bias_view 75 | output = torch.mul(output, self.update_mask) 76 | else: 77 | output = torch.mul(raw_out, self.mask_ratio) 78 | 79 | 80 | if self.return_mask: 81 | return output, self.update_mask 82 | else: 83 | return output 84 | -------------------------------------------------------------------------------- /model/simplenet.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | class Conv4(nn.Module): 5 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 6 | super().__init__(**kwargs) 7 | 8 | self.net = nn.Sequential( 9 | nn.Conv2d(input_channels, 16, 3, 1, 1), 10 | nn.ReLU(inplace=True), 11 | nn.Conv2d(16, 16, 3, 1, 1), 12 | nn.ReLU(inplace=True), 13 | nn.Conv2d(16, 16, 3, 1, 1), 14 | nn.ReLU(inplace=True), 15 | nn.Conv2d(16, 16, 3, 1, 1), 16 | nn.ReLU(inplace=True), 17 | nn.Conv2d(16, 16, 3, 1, 1), 18 | nn.ReLU(inplace=True), 19 | nn.Conv2d(16, num_classes, 1) 20 | ) 21 | 22 | def forward(self, x): 23 | x = self.net(x) 24 | return x 25 | 26 | class Conv1(nn.Module): 27 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 28 | super().__init__(**kwargs) 29 | 30 | self.net = nn.Sequential( 31 | nn.Conv2d(input_channels, 16, 3, 1, 1), 32 | nn.ReLU(inplace=True), 33 | nn.Conv2d(16, 16, 3, 1, 1), 34 | nn.ReLU(inplace=True), 35 | nn.Conv2d(16, num_classes, 1) 36 | ) 37 | 38 | def forward(self, x): 39 | x = self.net(x) 40 | return x 41 | 42 | class Linear(nn.Module): 43 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 44 | super().__init__(**kwargs) 45 | 46 | self.net = nn.Sequential( 47 | nn.Conv2d(input_channels, 16, 1), 48 | nn.ReLU(inplace=True), 49 | nn.Conv2d(16, num_classes, 1) 50 | ) 51 | 52 | def forward(self, x): 53 | x = self.net(x) 54 | return x 55 | 56 | class MLP(nn.Module): 57 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 58 | super().__init__(**kwargs) 59 | 60 | self.net = nn.Sequential( 61 | nn.Conv2d(input_channels, 8, 1), 62 | nn.ReLU(inplace=True), 63 | nn.Conv2d(8, 8, 1), 64 | nn.ReLU(inplace=True), 65 | nn.Conv2d(8, 8, 1), 66 | nn.ReLU(inplace=True), 67 | nn.Conv2d(8, 8, 1), 68 | nn.ReLU(inplace=True), 69 | nn.Conv2d(8, num_classes, 1) 70 | ) 71 | 72 | def forward(self, x): 73 | x = self.net(x) 74 | return x 75 | 76 | if __name__ == '__main__': 77 | from torchsummary import * 78 | summary(Conv1(input_channels=3),(3,64,64)) -------------------------------------------------------------------------------- /model/unet.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class ConvBActiv(nn.Module): 6 | def __init__(self, in_channels, middle_channels, out_channels): 7 | super().__init__() 8 | 9 | self.relu = nn.ReLU(inplace=True) 10 | self.conv1 = nn.Conv2d(in_channels, middle_channels, 3, 1, 1) 11 | self.bn1 = nn.BatchNorm2d(middle_channels) 12 | self.conv2 = nn.Conv2d(middle_channels, out_channels, 3, 1, 1) 13 | self.bn2 = nn.BatchNorm2d(out_channels) 14 | 15 | def forward(self, x): 16 | x = self.conv1(x) 17 | x = self.bn1(x) 18 | x = self.relu(x) 19 | x = self.conv2(x) 20 | x = self.bn2(x) 21 | x = self.relu(x) 22 | return x 23 | 24 | 25 | class ConvUNetBasicBlock(nn.Module): 26 | def __init__(self, input_channels=2, **kwargs): 27 | super().__init__() 28 | self.n_channels = input_channels 29 | 30 | self.bilinear = kwargs.get('bilinear', True) 31 | self.return_conf = kwargs.get('return_conf', False) 32 | factor = 2 33 | 34 | self.pool = nn.MaxPool2d(2, 2) 35 | self.up = nn.Upsample(scale_factor=2, 36 | mode='bilinear', 37 | align_corners=True) 38 | 39 | self.upmask = nn.Upsample(scale_factor=2, 40 | mode='nearest') 41 | 42 | self.nb_filter = [64, 128, 256, 512, 1024] 43 | self.conv0_0 = ConvBActiv(input_channels, self.nb_filter[0], self.nb_filter[0]) 44 | self.conv1_0 = ConvBActiv(self.nb_filter[0], self.nb_filter[1], self.nb_filter[1]) 45 | self.conv2_0 = ConvBActiv(self.nb_filter[1], self.nb_filter[2], self.nb_filter[2]) 46 | self.conv3_0 = ConvBActiv(self.nb_filter[2], self.nb_filter[3], self.nb_filter[3]) 47 | self.conv4_0 = ConvBActiv(self.nb_filter[3], self.nb_filter[4] // factor, self.nb_filter[4] // factor) 48 | 49 | self.conv3_1 = ConvBActiv(self.nb_filter[4], self.nb_filter[3] // factor, 50 | self.nb_filter[3] // factor) 51 | self.conv2_2 = ConvBActiv(self.nb_filter[3], self.nb_filter[2] // factor, 52 | self.nb_filter[2] // factor) 53 | self.conv1_3 = ConvBActiv(self.nb_filter[2], self.nb_filter[1] // factor, 54 | self.nb_filter[1] // factor) 55 | self.conv0_4 = ConvBActiv(self.nb_filter[1], self.nb_filter[0], 56 | self.nb_filter[0]) 57 | 58 | def forward(self, x): 59 | x0_0 = self.conv0_0(x) 60 | x1_0 = self.conv1_0(self.pool(x0_0)) 61 | x2_0 = self.conv2_0(self.pool(x1_0)) 62 | x3_0 = self.conv3_0(self.pool(x2_0)) 63 | x4_0 = self.conv4_0(self.pool(x3_0)) 64 | 65 | x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) 66 | x2_2 = self.conv2_2(torch.cat([x2_0, self.up(x3_1)], 1)) 67 | x1_3 = self.conv1_3(torch.cat([x1_0, self.up(x2_2)], 1)) 68 | x0_4 = self.conv0_4(torch.cat([x0_0, self.up(x1_3)], 1)) 69 | 70 | return x0_4, x1_3, x2_2, x3_1, x4_0 71 | 72 | 73 | class UNet(ConvUNetBasicBlock): 74 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 75 | super().__init__(input_channels, **kwargs) 76 | self.n_classes = num_classes 77 | 78 | self.final = nn.Conv2d(self.nb_filter[0], num_classes, 1) 79 | 80 | def forward(self, x): 81 | x0_4, x1_3, x2_2, x3_1, x4_0 = super().forward(x) 82 | 83 | x = self.final(x0_4) 84 | return x 85 | 86 | class UNetEx(ConvUNetBasicBlock): 87 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 88 | super().__init__(input_channels, **kwargs) 89 | self.n_classes = num_classes 90 | 91 | 92 | self.exconv1 = ConvBActiv(self.nb_filter[0], self.nb_filter[0]//2, self.nb_filter[0]//2) 93 | self.exconv2 = ConvBActiv(self.nb_filter[0]//2, self.nb_filter[0]//4, self.nb_filter[0]//4) 94 | # self.exconv3 = nn.Conv2d(32, 16, kernel_size=3, padding=1) 95 | self.final = nn.Conv2d(self.nb_filter[0]//4, num_classes, kernel_size=1) 96 | 97 | def forward(self, x): 98 | x0_4, x1_3, x2_2, x3_1, x4_0 = super().forward(x) 99 | 100 | x = self.exconv1(x0_4) 101 | x = self.exconv2(x) 102 | # x = self.exconv3(x) 103 | x = self.final(x) 104 | return x 105 | 106 | class UNet2Tasks(ConvUNetBasicBlock): 107 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 108 | super().__init__(input_channels, **kwargs) 109 | self.n_classes = num_classes 110 | 111 | self.final0 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 112 | self.final1 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 113 | 114 | def forward(self, x): 115 | x0_4, x1_3, x2_2, x3_1, x4_0 = super().forward(x) 116 | 117 | x0 = self.final0(x0_4) 118 | x1 = self.final1(x0_4) 119 | return x0, x1 120 | 121 | 122 | if __name__ == '__main__': 123 | from torchsummary import summary 124 | 125 | # summary(ConvBActiv(2,64,64), (2, 256, 256)) 126 | summary(UNetEx().cuda(), (2, 256, 256)) 127 | -------------------------------------------------------------------------------- /model/unet_edg.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class ConvBActiv(nn.Module): 6 | def __init__(self, in_channels, middle_channels, out_channels): 7 | super().__init__() 8 | 9 | self.relu = nn.ReLU(inplace=True) 10 | self.conv1 = nn.Conv2d(in_channels, middle_channels, 3, 1, 1) 11 | self.bn1 = nn.BatchNorm2d(middle_channels) 12 | self.conv2 = nn.Conv2d(middle_channels, out_channels, 3, 1, 1) 13 | self.bn2 = nn.BatchNorm2d(out_channels) 14 | 15 | def forward(self, x): 16 | x = self.conv1(x) 17 | x = self.bn1(x) 18 | x = self.relu(x) 19 | x = self.conv2(x) 20 | x = self.bn2(x) 21 | x = self.relu(x) 22 | return x 23 | 24 | 25 | class ConvUNetBasicBlock(nn.Module): 26 | def __init__(self, input_channels=2, **kwargs): 27 | super().__init__() 28 | self.n_channels = input_channels 29 | 30 | self.bilinear = kwargs.get('bilinear', True) 31 | self.return_conf = kwargs.get('return_conf', False) 32 | factor = 2 33 | 34 | self.pool = nn.MaxPool2d(2, 2) 35 | self.up = nn.Upsample(scale_factor=2, 36 | mode='bilinear', 37 | align_corners=True) 38 | 39 | self.upmask = nn.Upsample(scale_factor=2, 40 | mode='nearest') 41 | 42 | self.nb_filter = [64, 128, 256, 512, 1024] 43 | self.econv0_0 = ConvBActiv(input_channels, self.nb_filter[0], self.nb_filter[0]) 44 | self.econv1_0 = ConvBActiv(self.nb_filter[0], self.nb_filter[1], self.nb_filter[1]) 45 | self.econv2_0 = ConvBActiv(self.nb_filter[1], self.nb_filter[2], self.nb_filter[2]) 46 | self.econv3_0 = ConvBActiv(self.nb_filter[2], self.nb_filter[3], self.nb_filter[3]) 47 | self.econv4_0 = ConvBActiv(self.nb_filter[3], self.nb_filter[4] // factor, self.nb_filter[4] // factor) 48 | 49 | self.dconv3_1 = ConvBActiv(self.nb_filter[4], self.nb_filter[3] // factor, 50 | self.nb_filter[3] // factor) 51 | self.dconv2_2 = ConvBActiv(self.nb_filter[3], self.nb_filter[2] // factor, 52 | self.nb_filter[2] // factor) 53 | self.dconv1_3 = ConvBActiv(self.nb_filter[2], self.nb_filter[1] // factor, 54 | self.nb_filter[1] // factor) 55 | self.dconv0_4 = ConvBActiv(self.nb_filter[1], self.nb_filter[0], 56 | self.nb_filter[0]) 57 | self.gconv3_1 = ConvBActiv(self.nb_filter[4], self.nb_filter[3] // factor, 58 | self.nb_filter[3] // factor) 59 | self.gconv2_2 = ConvBActiv(self.nb_filter[3], self.nb_filter[2] // factor, 60 | self.nb_filter[2] // factor) 61 | self.gconv1_3 = ConvBActiv(self.nb_filter[2], self.nb_filter[1] // factor, 62 | self.nb_filter[1] // factor) 63 | self.gconv0_4 = ConvBActiv(self.nb_filter[1], self.nb_filter[0], 64 | self.nb_filter[0]) 65 | def forward(self, x): 66 | x0_0 = self.econv0_0(x) 67 | x1_0 = self.econv1_0(self.pool(x0_0)) 68 | x2_0 = self.econv2_0(self.pool(x1_0)) 69 | x3_0 = self.econv3_0(self.pool(x2_0)) 70 | x4_0 = self.econv4_0(self.pool(x3_0)) 71 | 72 | d3_1 = self.dconv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) 73 | d2_2 = self.dconv2_2(torch.cat([x2_0, self.up(d3_1)], 1)) 74 | d1_3 = self.dconv1_3(torch.cat([x1_0, self.up(d2_2)], 1)) 75 | d0_4 = self.dconv0_4(torch.cat([x0_0, self.up(d1_3)], 1)) 76 | 77 | g3_1 = self.gconv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) 78 | g2_2 = self.gconv2_2(torch.cat([x2_0, self.up(g3_1)], 1)) 79 | g1_3 = self.gconv1_3(torch.cat([x1_0, self.up(g2_2)], 1)) 80 | g0_4 = self.gconv0_4(torch.cat([x0_0, self.up(g1_3)], 1)) 81 | 82 | return d0_4, d1_3, d2_2, d3_1, g0_4, g1_3, g2_2, g3_1 83 | 84 | class UNetEDG(ConvUNetBasicBlock): 85 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 86 | super().__init__(input_channels, **kwargs) 87 | self.n_classes = num_classes 88 | 89 | self.final0 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 90 | self.final1 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 91 | 92 | def forward(self, x): 93 | d0_4, d1_3, d2_2, d3_1, g0_4, g1_3, g2_2, g3_1 = super().forward(x) 94 | 95 | x0 = self.final0(d0_4) 96 | x1 = self.final1(g0_4) 97 | return x0, x1 98 | 99 | 100 | if __name__ == '__main__': 101 | from torchsummary import summary 102 | 103 | summary(UNetEDG(), (2, 64, 64)) 104 | -------------------------------------------------------------------------------- /model/unet_nobn.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class ConvActiv(nn.Module): 6 | def __init__(self, in_channels, middle_channels, out_channels): 7 | super().__init__() 8 | 9 | self.relu = nn.ReLU(inplace=True) 10 | self.conv1 = nn.Conv2d(in_channels, middle_channels, 3, 1, 1) 11 | self.conv2 = nn.Conv2d(middle_channels, out_channels, 3, 1, 1) 12 | 13 | def forward(self, x): 14 | x = self.conv1(x) 15 | x = self.relu(x) 16 | x = self.conv2(x) 17 | x = self.relu(x) 18 | return x 19 | 20 | 21 | class ConvNOBNUNetBasicBlock(nn.Module): 22 | def __init__(self, input_channels=2, **kwargs): 23 | super().__init__() 24 | self.n_channels = input_channels 25 | 26 | self.bilinear = kwargs.get('bilinear', True) 27 | self.return_conf = kwargs.get('return_conf', False) 28 | factor = 2 29 | 30 | self.pool = nn.MaxPool2d(2, 2) 31 | self.up = nn.Upsample(scale_factor=2, 32 | mode='bilinear', 33 | align_corners=True) 34 | 35 | self.upmask = nn.Upsample(scale_factor=2, 36 | mode='nearest') 37 | 38 | self.nb_filter = [64, 128, 256, 512, 1024] 39 | self.conv0_0 = ConvActiv(input_channels, self.nb_filter[0], self.nb_filter[0]) 40 | self.conv1_0 = ConvActiv(self.nb_filter[0], self.nb_filter[1], self.nb_filter[1]) 41 | self.conv2_0 = ConvActiv(self.nb_filter[1], self.nb_filter[2], self.nb_filter[2]) 42 | self.conv3_0 = ConvActiv(self.nb_filter[2], self.nb_filter[3], self.nb_filter[3]) 43 | self.conv4_0 = ConvActiv(self.nb_filter[3], self.nb_filter[4] // factor, self.nb_filter[4] // factor) 44 | 45 | self.conv3_1 = ConvActiv(self.nb_filter[4], self.nb_filter[3] // factor, 46 | self.nb_filter[3] // factor) 47 | self.conv2_2 = ConvActiv(self.nb_filter[3], self.nb_filter[2] // factor, 48 | self.nb_filter[2] // factor) 49 | self.conv1_3 = ConvActiv(self.nb_filter[2], self.nb_filter[1] // factor, 50 | self.nb_filter[1] // factor) 51 | self.conv0_4 = ConvActiv(self.nb_filter[1], self.nb_filter[0], 52 | self.nb_filter[0]) 53 | 54 | def forward(self, x): 55 | x0_0 = self.conv0_0(x) 56 | x1_0 = self.conv1_0(self.pool(x0_0)) 57 | x2_0 = self.conv2_0(self.pool(x1_0)) 58 | x3_0 = self.conv3_0(self.pool(x2_0)) 59 | x4_0 = self.conv4_0(self.pool(x3_0)) 60 | 61 | x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) 62 | x2_2 = self.conv2_2(torch.cat([x2_0, self.up(x3_1)], 1)) 63 | x1_3 = self.conv1_3(torch.cat([x1_0, self.up(x2_2)], 1)) 64 | x0_4 = self.conv0_4(torch.cat([x0_0, self.up(x1_3)], 1)) 65 | 66 | return x0_4, x1_3, x2_2, x3_1, x4_0 67 | 68 | 69 | class UNetNOBN(ConvNOBNUNetBasicBlock): 70 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 71 | super().__init__(input_channels, **kwargs) 72 | self.n_classes = num_classes 73 | 74 | self.final = nn.Conv2d(self.nb_filter[0], num_classes, 1) 75 | 76 | def forward(self, x): 77 | x0_4, x1_3, x2_2, x3_1, x4_0 = super().forward(x) 78 | 79 | x = self.final(x0_4) 80 | return x 81 | 82 | class UNet2Tasks(ConvNOBNUNetBasicBlock): 83 | def __init__(self, num_classes=1, input_channels=2, **kwargs): 84 | super().__init__(input_channels, **kwargs) 85 | self.n_classes = num_classes 86 | 87 | self.final0 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 88 | self.final1 = nn.Conv2d(self.nb_filter[0], num_classes, 1) 89 | 90 | def forward(self, x): 91 | x0_4, x1_3, x2_2, x3_1, x4_0 = super().forward(x) 92 | 93 | x0 = self.final0(x0_4) 94 | x1 = self.final1(x0_4) 95 | return x0, x1 96 | 97 | 98 | if __name__ == '__main__': 99 | from torchsummary import summary 100 | 101 | summary(UNetNOBN(), (2, 64, 64)) 102 | -------------------------------------------------------------------------------- /model/vvvnet.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.functional as F 4 | from model import * 5 | 6 | class VVVNet(nn.Module): 7 | def __init__(self, arch, trainable=[True,True,True], multitask = False): 8 | super().__init__() 9 | self.multitask = multitask 10 | assert(len(arch) == 3) 11 | self.net = nn.ModuleList() 12 | self.trainable = trainable 13 | for a in arch: 14 | try: 15 | _n = eval(a) 16 | # cmd = f'_n = {a}' 17 | # exec(cmd) 18 | # print(cmd) 19 | assert (_n is not None) 20 | self.net.append(_n) 21 | except Exception as e: 22 | raise RuntimeError(f'net architecture {a} init failed:\n {e}') 23 | 24 | assert (len(self.net) == 3) 25 | assert (len(self.trainable ) == 3) 26 | 27 | def forward(self, x): 28 | input_depth = x[:,0:1,:,:] 29 | input_mask = x[:,1:2,:,:] # second channel, the mask 30 | pred_vis = torch.sigmoid(self.net[0](x)) 31 | pred_vis2 = torch.sigmoid(self.net[1](torch.cat([x, pred_vis], dim=1))) 32 | pred_finevis = self.net[2](torch.cat([x, pred_vis2], dim=1)) 33 | 34 | if self.multitask: 35 | return pred_vis, pred_vis2, pred_finevis 36 | else: 37 | return pred_finevis 38 | 39 | def train(self, mode=True): 40 | super().train(mode) 41 | for i in range(len(self.net)): 42 | if self.trainable[i]: 43 | self.net[i].train(mode) 44 | else: 45 | self.net[i].eval() 46 | 47 | 48 | def cvtCheckpoint3to1(arch,input,output): 49 | n = VVVNet(arch) 50 | statedicts = torch.load(input) 51 | n.net[0].load_state_dict(statedicts['net0']) 52 | n.net[1].load_state_dict(statedicts['net1']) 53 | n.net[2].load_state_dict(statedicts['net2']) 54 | torch.save(n.state_dict(), output) 55 | return n 56 | 57 | if __name__ == '__main__': 58 | device = torch.device('cuda') 59 | arch = ['UNet(input_channels=2)', 'UNet(input_channels=3)', 'UNet(input_channels=3)'] 60 | 61 | old_weight = "/home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISVISVIS_['UNet(input_channels=2)', 'UNet(input_channels=3)', 'UNet(input_channels=3)']_epoch100.pth" 62 | new_weight = "/home/sxs/GDA/cvpr21/visibility_learning_pytorch/checkpoints/VISVISVIS_UUU_epoch100.pth" 63 | 64 | net = cvtCheckpoint3to1(arch,old_weight,new_weight).to(device=device) 65 | 66 | import torchsummary 67 | torchsummary.summary(net,(2,256,256)) -------------------------------------------------------------------------------- /setup_tools.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ## Docker 4 | export DEBIAN_FRONTEND=noninteractive 5 | ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime 6 | apt-get update && apt-get install -yqq --no-install-recommends \ 7 | libglvnd0 libgl1 libglx0 \ 8 | libegl1 libxext6 libx11-6 \ 9 | wget gpg sudo curl 10 | 11 | # Install System Packages 12 | apt-get install -yqq --no-install-recommends \ 13 | git ca-certificates build-essential \ 14 | libglu1-mesa-dev libegl1-mesa-dev freeglut3-dev libglew-dev \ 15 | libglfw3-dev libpng-dev libjpeg-dev libtiff-dev \ 16 | libboost-iostreams-dev libboost-program-options-dev \ 17 | libboost-system-dev libboost-serialization-dev \ 18 | libopencv-dev libcgal-dev libeigen3-dev libpcl-dev 19 | 20 | conda install -yq cmake 21 | pip install -qq "conan<2" open3d imageio gdown 22 | 23 | # Clean Cache 24 | rm -rf ./tools/vvmesh_build ./tools/openMVS_build ./tools/bin ./tools/lib ./tools/include ./tools/vcglib 25 | # Build vvmesh 26 | ./tools/build_vvmesh.sh 27 | # Build OpenMVS 28 | ./tools/build_openmvs.sh 29 | # Clean Build cache 30 | rm -rf ./tools/vvmesh_build ./tools/openMVS_build -------------------------------------------------------------------------------- /tools/build_openmvs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 3 | echo "Installing.. $SCRIPT_DIR" 4 | git clone https://github.com/cdcseacave/VCG.git "$SCRIPT_DIR/vcglib" -q 5 | cd "$SCRIPT_DIR/vcglib" && git checkout 88f12f212a1645d1fa6416592a434c29e63b57f0 6 | git clone https://github.com/GDAOSU/openMVS_mvasupport.git "$SCRIPT_DIR/openMVS_src" -q 7 | cd "$SCRIPT_DIR/openMVS_src" && git checkout 09fdd45e23c4b4fd3a0a4258f8294aae6e9fe8d9 8 | mkdir "$SCRIPT_DIR/openMVS_build" 9 | cd "$SCRIPT_DIR/openMVS_build" 10 | cmake . "$SCRIPT_DIR/openMVS_src" -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT="$SCRIPT_DIR/vcglib" -DCMAKE_INSTALL_PREFIX="$SCRIPT_DIR" 11 | make -j7 && make install 12 | -------------------------------------------------------------------------------- /tools/build_vvmesh.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Rebuild VVMesh 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 4 | conan export $SCRIPT_DIR/vvmesh_src/cmake/conan/qhullcpp sxsong1207/stable 5 | conan export $SCRIPT_DIR/vvmesh_src/cmake/conan/openvolumemesh sxsong1207/stable 6 | mkdir "$SCRIPT_DIR/vvmesh_build" && cd "$SCRIPT_DIR/vvmesh_build" 7 | 8 | PYTHON_EXE=`which python` 9 | cd "$SCRIPT_DIR/vvmesh_build" 10 | cmake . "$SCRIPT_DIR/vvmesh_src" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$SCRIPT_DIR -DPYTHON_EXECUTABLE=$PYTHON_EXE 11 | make -j7 && make install 12 | -------------------------------------------------------------------------------- /tools/vvmesh_src/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Google 4 | AccessModifierOffset: -1 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveMacros: false 7 | AlignConsecutiveAssignments: false 8 | AlignConsecutiveDeclarations: false 9 | AlignEscapedNewlines: Left 10 | AlignOperands: true 11 | AlignTrailingComments: true 12 | AllowAllArgumentsOnNextLine: true 13 | AllowAllConstructorInitializersOnNextLine: true 14 | AllowAllParametersOfDeclarationOnNextLine: true 15 | AllowShortBlocksOnASingleLine: Never 16 | AllowShortCaseLabelsOnASingleLine: false 17 | AllowShortFunctionsOnASingleLine: All 18 | AllowShortLambdasOnASingleLine: All 19 | AllowShortIfStatementsOnASingleLine: WithoutElse 20 | AllowShortLoopsOnASingleLine: true 21 | AlwaysBreakAfterDefinitionReturnType: None 22 | AlwaysBreakAfterReturnType: None 23 | AlwaysBreakBeforeMultilineStrings: true 24 | AlwaysBreakTemplateDeclarations: Yes 25 | BinPackArguments: true 26 | BinPackParameters: true 27 | BraceWrapping: 28 | AfterCaseLabel: false 29 | AfterClass: false 30 | AfterControlStatement: false 31 | AfterEnum: false 32 | AfterFunction: false 33 | AfterNamespace: false 34 | AfterObjCDeclaration: false 35 | AfterStruct: false 36 | AfterUnion: false 37 | AfterExternBlock: false 38 | BeforeCatch: false 39 | BeforeElse: false 40 | IndentBraces: false 41 | SplitEmptyFunction: true 42 | SplitEmptyRecord: true 43 | SplitEmptyNamespace: true 44 | BreakBeforeBinaryOperators: None 45 | BreakBeforeBraces: Attach 46 | BreakBeforeInheritanceComma: false 47 | BreakInheritanceList: BeforeColon 48 | BreakBeforeTernaryOperators: true 49 | BreakConstructorInitializersBeforeComma: false 50 | BreakConstructorInitializers: BeforeColon 51 | BreakAfterJavaFieldAnnotations: false 52 | BreakStringLiterals: true 53 | ColumnLimit: 80 54 | CommentPragmas: '^ IWYU pragma:' 55 | CompactNamespaces: false 56 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 57 | ConstructorInitializerIndentWidth: 4 58 | ContinuationIndentWidth: 4 59 | Cpp11BracedListStyle: true 60 | DeriveLineEnding: true 61 | DerivePointerAlignment: true 62 | DisableFormat: false 63 | ExperimentalAutoDetectBinPacking: false 64 | FixNamespaceComments: true 65 | ForEachMacros: 66 | - foreach 67 | - Q_FOREACH 68 | - BOOST_FOREACH 69 | IncludeBlocks: Preserve 70 | IncludeCategories: 71 | - Regex: '^' 72 | Priority: 2 73 | SortPriority: 0 74 | - Regex: '^<.*\.h>' 75 | Priority: 1 76 | SortPriority: 0 77 | - Regex: '^<.*' 78 | Priority: 2 79 | SortPriority: 0 80 | - Regex: '.*' 81 | Priority: 3 82 | SortPriority: 0 83 | IncludeIsMainRegex: '([-_](test|unittest))?$' 84 | IncludeIsMainSourceRegex: '' 85 | IndentCaseLabels: true 86 | IndentGotoLabels: true 87 | IndentPPDirectives: None 88 | IndentWidth: 2 89 | IndentWrappedFunctionNames: false 90 | JavaScriptQuotes: Leave 91 | JavaScriptWrapImports: true 92 | KeepEmptyLinesAtTheStartOfBlocks: false 93 | MacroBlockBegin: '' 94 | MacroBlockEnd: '' 95 | MaxEmptyLinesToKeep: 1 96 | NamespaceIndentation: None 97 | ObjCBinPackProtocolList: Never 98 | ObjCBlockIndentWidth: 2 99 | ObjCSpaceAfterProperty: false 100 | ObjCSpaceBeforeProtocolList: true 101 | PenaltyBreakAssignment: 2 102 | PenaltyBreakBeforeFirstCallParameter: 1 103 | PenaltyBreakComment: 300 104 | PenaltyBreakFirstLessLess: 120 105 | PenaltyBreakString: 1000 106 | PenaltyBreakTemplateDeclaration: 10 107 | PenaltyExcessCharacter: 1000000 108 | PenaltyReturnTypeOnItsOwnLine: 200 109 | PointerAlignment: Left 110 | RawStringFormats: 111 | - Language: Cpp 112 | Delimiters: 113 | - cc 114 | - CC 115 | - cpp 116 | - Cpp 117 | - CPP 118 | - 'c++' 119 | - 'C++' 120 | CanonicalDelimiter: '' 121 | BasedOnStyle: google 122 | - Language: TextProto 123 | Delimiters: 124 | - pb 125 | - PB 126 | - proto 127 | - PROTO 128 | EnclosingFunctions: 129 | - EqualsProto 130 | - EquivToProto 131 | - PARSE_PARTIAL_TEXT_PROTO 132 | - PARSE_TEST_PROTO 133 | - PARSE_TEXT_PROTO 134 | - ParseTextOrDie 135 | - ParseTextProtoOrDie 136 | CanonicalDelimiter: '' 137 | BasedOnStyle: google 138 | ReflowComments: true 139 | SortIncludes: false 140 | SortUsingDeclarations: true 141 | SpaceAfterCStyleCast: false 142 | SpaceAfterLogicalNot: false 143 | SpaceAfterTemplateKeyword: true 144 | SpaceBeforeAssignmentOperators: true 145 | SpaceBeforeCpp11BracedList: false 146 | SpaceBeforeCtorInitializerColon: true 147 | SpaceBeforeInheritanceColon: true 148 | SpaceBeforeParens: ControlStatements 149 | SpaceBeforeRangeBasedForLoopColon: true 150 | SpaceInEmptyBlock: false 151 | SpaceInEmptyParentheses: false 152 | SpacesBeforeTrailingComments: 2 153 | SpacesInAngles: false 154 | SpacesInConditionalStatement: false 155 | SpacesInContainerLiterals: true 156 | SpacesInCStyleCastParentheses: false 157 | SpacesInParentheses: false 158 | SpacesInSquareBrackets: false 159 | SpaceBeforeSquareBrackets: false 160 | Standard: Auto 161 | StatementMacros: 162 | - Q_UNUSED 163 | - QT_REQUIRE_VERSION 164 | TabWidth: 8 165 | UseCRLF: false 166 | UseTab: Never 167 | ... 168 | 169 | -------------------------------------------------------------------------------- /tools/vvmesh_src/.gitignore: -------------------------------------------------------------------------------- 1 | /cmake-build-*/** 2 | *.obj 3 | *.mva 4 | .idea 5 | .dir-locals.el 6 | *.pth 7 | *.ovm 8 | **/build/* 9 | **/tmp/* 10 | *.so 11 | **/.eggs/* 12 | /testdata/* 13 | /cmake-build-*/ 14 | **/generated/* 15 | workspace.code-workspace 16 | .vscode/ 17 | /apps/wwzb_filter/test/ 18 | /apps/normalestimation/test/ 19 | cache.pk 20 | **/ignore/** 21 | .vs/ 22 | CMakeSettings.json 23 | /external/ 24 | /hunter_deps/ -------------------------------------------------------------------------------- /tools/vvmesh_src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | # Set policies 3 | cmake_policy(SET CMP0072 NEW) 4 | # Start Project 5 | project(VVMESH 6 | LANGUAGES CXX 7 | VERSION 0.8.0) 8 | 9 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 10 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 11 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 12 | 13 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) 14 | list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}) 15 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 16 | 17 | #### Compiler traits 18 | if (NOT CMAKE_BUILD_TYPE) 19 | set(CMAKE_BUILD_TYPE Release) 20 | endif () 21 | set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ version selection") # or 11, 14, 17, 20 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) # optional, ensure standard is supported 23 | set(CMAKE_CXX_EXTENSIONS OFF) # optional, keep compiler extensionsn off 24 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 25 | if (WIN32) 26 | add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX) 27 | endif () 28 | 29 | # RPath 30 | set(CMAKE_SKIP_BUILD_RPATH FALSE) 31 | set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 32 | set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") 33 | ### Options 34 | 35 | option(BUILD_SHARED_PLUGINS "BUILD Plugins as shared libraries" ON) 36 | 37 | ############################### 38 | ## Solve dependencies 39 | include(BuildExternalDeps) 40 | 41 | find_package(Threads REQUIRED) 42 | find_package(OpenMP) 43 | if (OPENMP_FOUND) 44 | message("++ Enable OpenMP support") 45 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 46 | add_definitions(-D_USE_OPENMP) 47 | set(_USE_OPENMP TRUE) 48 | else () 49 | message("-- Can't find OpenMP. Continuing without it.") 50 | endif () 51 | 52 | if (WIN32) 53 | find_package(unofficial-angle CONFIG REQUIRED) 54 | find_package(OpenGL REQUIRED COMPONENTS OpenGL) 55 | else () 56 | find_package(OpenGL REQUIRED COMPONENTS OpenGL EGL) 57 | endif () 58 | 59 | if (OPENGL_FOUND) 60 | message("++ Enable OpenGL support") 61 | include_directories(${OPENGL_INCLUDE_DIR}) 62 | add_definitions(${OpenGL_DEFINITIONS}) 63 | add_definitions(-D_USE_OPENGL) 64 | set(_USE_OPENGL TRUE) 65 | else () 66 | message("-- Can't find OpenGL. Continuing without it.") 67 | endif () 68 | 69 | #find_package(CUDA) 70 | #if(CUDA_FOUND) 71 | # include_directories(${CUDA_INCLUDE_DIRS}) 72 | # add_definitions(-D_USE_CUDA) 73 | # set(_USE_CUDA TRUE) 74 | #else() 75 | # set(CUDA_CUDA_LIBRARY "") 76 | # message("-- Can't find CUDA. Continuing without it.") 77 | #endif() 78 | 79 | if(QHULL_FOUND) 80 | message("++ Enable QHULL support") 81 | include_directories(${QHULL_INCLUDE_DIRS}) 82 | add_definitions(${QHULL_DEFINITIONS}) 83 | endif() 84 | 85 | if (Boost_FOUND) 86 | message("++ Enable Boost support") 87 | include_directories(${Boost_INCLUDE_DIRS}) 88 | add_definitions(${Boost_DEFINITIONS} -D_USE_BOOST) 89 | link_directories(${Boost_LIBRARY_DIRS}) 90 | SET(_USE_BOOST TRUE) 91 | endif () 92 | 93 | if (EIGEN_FOUND) 94 | message("++ Enable Eigen3 support") 95 | include_directories(${EIGEN3_INCLUDE_DIRS}) 96 | add_definitions(${EIGEN3_DEFINITIONS}) 97 | add_definitions(-D_USE_EIGEN) 98 | endif () 99 | 100 | if (PCL_FOUND) 101 | message("++ Enable PCL support") 102 | include_directories(${PCL_INCLUDE_DIRS}) 103 | add_definitions(${PCL_DEFINITIONS}) 104 | endif() 105 | 106 | if (OpenCV_FOUND) 107 | message("++ Enable OpenCV support") 108 | include_directories(${opencv_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) 109 | add_definitions(-D_USE_OPENCV) 110 | endif () 111 | 112 | if (spdlog_FOUND) 113 | include_directories(${spdlog_INCLUDE_DIRS}) 114 | add_definitions(${spdlog_DEFINITIONS}) 115 | endif () 116 | 117 | if(fmt_FOUND) 118 | include_directories(${fmt_INCLUDE_DIRS}) 119 | endif() 120 | 121 | # Please uncomment following line and supply compressed_streams package 122 | # add_definitions(-D_USE_COMPRESSED_STREAMS) 123 | if(jsoncpp_FOUND) 124 | message("++ Enable Jsoncpp") 125 | include_directories(${jsoncpp_INCLUDE_DIRS}) 126 | endif() 127 | if (zstd_FOUND) 128 | message("++ Enable ZSTDStream Archive Format") 129 | add_definitions(-D_USE_ZSTDSTREAM) 130 | include_directories(${zstd_INCLUDE_DIRS}) 131 | endif () 132 | if (ZLIB_FOUND) 133 | message("++ Enable GZStream Archive Format") 134 | add_definitions(-D_USE_GZSTREAM) 135 | endif () 136 | 137 | ################### End Dependancy 138 | enable_testing() 139 | 140 | include_directories(src) 141 | 142 | add_subdirectory(src) 143 | add_subdirectory(apps) 144 | 145 | 146 | -------------------------------------------------------------------------------- /tools/vvmesh_src/README.md: -------------------------------------------------------------------------------- 1 | # Virtual Visibility Toolkit 2 | 3 | ## Installation 4 | 5 | ```shell 6 | sudo apt install -y pcl python3-pip 7 | pip install conan 8 | conan create cmake/conan/openvolumemesh sxsong1207/stable 9 | conan create cmake/conan/qhullcpp sxsong1207/stable 10 | ``` 11 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(simplecamcreator) 3 | add_subdirectory(glrender) 4 | add_subdirectory(visibility_filter) 5 | add_subdirectory(bundle_packing) 6 | add_subdirectory(visibility_network) 7 | add_subdirectory(vvtool) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/bundle_packing/CLOUD_BUNDLE_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOUD_BUNDLE_PLUGIN_H 2 | #define CLOUD_BUNDLE_PLUGIN_H 3 | 4 | #include "Plugin/plugininterface.h" 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | class DLL_API CLOUD_BUNDLE_Plugin : public PluginInterface { 15 | public: 16 | virtual std::string getWorkerName(); 17 | virtual bool operator()(const nlohmann::json& blockJson); 18 | 19 | private: 20 | const char* WORKER_NAME = "CLOUD_BUNDLE"; 21 | 22 | bool processBlock(const nlohmann::json& blockJson); 23 | 24 | private: 25 | bool exists_test(const std::string& name); 26 | 27 | struct RayBundle { 28 | std::string id_img; 29 | std::string conf_img; 30 | std::string rgb_img; 31 | Eigen::Matrix3f K; 32 | Eigen::Matrix3f R; 33 | Eigen::Vector3f C; 34 | int width; 35 | int height; 36 | }; 37 | 38 | size_t read_ptsply_mva(const std::string& filepath, MVSA::Interface& obj); 39 | 40 | bool read_RayBundles_json(const nlohmann::json& input_rays, 41 | std::vector& raybundles); 42 | 43 | bool set_cameras_mva(const std::vector& raybundles, 44 | MVSA::Interface& obj, bool normalize_K); 45 | 46 | bool set_rays_mva(const std::vector& raybundles, 47 | double conf_threshold, 48 | MVSA::Interface& obj); 49 | }; 50 | #endif // CLOUD_BUNDLE_PLUGIN_H 51 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/bundle_packing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Plugin libs #### 2 | if(BUILD_SHARED_PLUGINS) 3 | add_library(CLOUD_BUNDLE_plugin SHARED CLOUD_BUNDLE_plugin.cpp) 4 | target_compile_definitions(CLOUD_BUNDLE_plugin PRIVATE PLUGIN_DLL_EXPORTS) 5 | else() 6 | add_library(CLOUD_BUNDLE_plugin STATIC CLOUD_BUNDLE_plugin.cpp) 7 | endif() 8 | message("Opencv libs" ${opencv_LIBRARIES_TARGETS}) 9 | message("tinyply " ${tinyply_LIBRARIES_TARGETS}) 10 | target_include_directories(CLOUD_BUNDLE_plugin INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 11 | target_include_directories(CLOUD_BUNDLE_plugin PRIVATE ${tinyply_INCLUDE_DIRS}) 12 | target_link_libraries(CLOUD_BUNDLE_plugin 13 | PUBLIC PluginInterface 14 | PRIVATE MVArchive tinyply::tinyply 15 | ${OpenCV_LIBS} pcl_io) 16 | 17 | install(TARGETS CLOUD_BUNDLE_plugin 18 | RUNTIME DESTINATION bin 19 | ARCHIVE DESTINATION lib 20 | LIBRARY DESTINATION lib 21 | PUBLIC_HEADER DESTINATION include/plugins) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/bundle_packing/bundle_packing_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "Plugin/pluginmanager.h" 6 | 7 | #include "CLOUD_BUNDLE_plugin.h" 8 | 9 | void printUsage() { printf("Usage: [executable] input_json\n"); } 10 | 11 | int main(int argc, char** argv) { 12 | if (argc < 2) { 13 | printUsage(); 14 | return 0; 15 | } 16 | std::string input_param_path = argv[1]; 17 | if (input_param_path.empty()) { 18 | printUsage(); 19 | return 0; 20 | } 21 | 22 | nlohmann::json rootJson; 23 | { 24 | std::ifstream ifs(input_param_path, std::ifstream::binary); 25 | ifs >> rootJson; 26 | ifs.close(); 27 | } 28 | 29 | PluginManager pm; 30 | pm.registerPlugin(std::make_shared()); 31 | if (rootJson.is_array()) { 32 | printf("Array Mode\n"); 33 | for (auto& j : rootJson) { 34 | pm.callPlugin(j); 35 | } 36 | } else { 37 | printf("Single block Mode\n"); 38 | pm.callPlugin(rootJson); 39 | } 40 | 41 | printf("Done\n"); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/glrender/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Plugin libs #### 2 | set(SRCS GLRENDER_plugin.cpp) 3 | set(HEADERS GLRENDER_plugin.h) 4 | if(BUILD_SHARED_PLUGINS) 5 | add_library(GLRENDER_plugin SHARED ${SRCS}) 6 | target_compile_definitions(GLRENDER_plugin PRIVATE PLUGIN_DLL_EXPORTS) 7 | else() 8 | add_library(GLRENDER_plugin STATIC ${SRCS}) 9 | endif() 10 | 11 | target_include_directories(GLRENDER_plugin INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 12 | target_link_libraries(GLRENDER_plugin 13 | PUBLIC FBORender PluginInterface 14 | PRIVATE MVArchive OBJFile pcl_io pcl_kdtree) 15 | set_target_properties(GLRENDER_plugin PROPERTIES 16 | PUBLIC_HEADER "${HEADERS}") 17 | 18 | install(TARGETS GLRENDER_plugin 19 | RUNTIME DESTINATION bin 20 | ARCHIVE DESTINATION lib 21 | LIBRARY DESTINATION lib 22 | PUBLIC_HEADER DESTINATION include) 23 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/glrender/GLRENDER_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef GLRENDER_PLUGIN_H 2 | #define GLRENDER_PLUGIN_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Plugin/plugininterface.h" 8 | 9 | namespace FBORender { class MultidrawFBO; }; 10 | 11 | class GLRENDER_Plugin : public PluginInterface { 12 | public: 13 | GLRENDER_Plugin(std::shared_ptr pFBO); 14 | virtual std::string getWorkerName(); 15 | virtual bool operator()(const nlohmann::json &blockJson); 16 | virtual nlohmann::json getDefaultParameters(); 17 | private: 18 | const char *WORKER_NAME = "GLRENDER"; 19 | std::shared_ptr fbo; 20 | 21 | bool ensureFolderExist(std::string path); 22 | bool processBlock(const nlohmann::json &blockJson); 23 | }; 24 | #endif // GLRENDER_PLUGIN_H 25 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/glrender/env_setup.h: -------------------------------------------------------------------------------- 1 | #ifndef ENV_SETUP_H 2 | #define ENV_SETUP_H 3 | #include "FBORender/FBORender.h" 4 | #include 5 | 6 | static std::shared_ptr fbo; 7 | 8 | inline bool setup() { 9 | if (!fbo) { 10 | fbo.reset(new FBORender::MultidrawFBO); 11 | } 12 | FBORender::initGLContext(); 13 | FBORender::GLMakeContextCurrent(); 14 | return true; 15 | } 16 | #endif // ENV_SETUP_H 17 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/glrender/glrender_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "env_setup.h" 6 | #include "Plugin/pluginmanager.h" 7 | #include "GLRENDER_plugin.h" 8 | 9 | void printUsage() { printf("Usage: [executable] input_json\n"); } 10 | 11 | int main(int argc, char** argv) { 12 | if (argc < 2) { 13 | printUsage(); 14 | return 0; 15 | } 16 | std::string input_param_path = argv[1]; 17 | if (input_param_path.empty()) { 18 | printUsage(); 19 | return 0; 20 | } 21 | 22 | nlohmann::json rootJson; 23 | { 24 | std::ifstream ifs(input_param_path, std::ifstream::binary); 25 | ifs >> rootJson; 26 | ifs.close(); 27 | } 28 | 29 | setup(); 30 | 31 | PluginManager pm; 32 | pm.registerPlugin(std::make_shared(fbo)); 33 | if (rootJson.is_array()) { 34 | for (auto& j : rootJson) pm.callPlugin(j); 35 | } else { 36 | pm.callPlugin(rootJson); 37 | } 38 | printf("Done\n"); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/simplecamcreator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES o3d_vvcreator.py 2 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 3 | DESTINATION bin) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/simplecamcreator/o3d_vvcreator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import os.path as osp 4 | import sys 5 | import json 6 | import math 7 | import argparse 8 | import open3d as o3d 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | 12 | 13 | def parseArgs(): 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('cloud', type=str, help='input point cloud') 16 | parser.add_argument('-il', '--input_list', help='initial camera json list') 17 | parser.add_argument('-ol', '--output_list', help='output camera json list') 18 | 19 | parser.add_argument('--focal', type=float, default=300, help='focal length') 20 | parser.add_argument('--width', type=int, default=512, help='camera width') 21 | parser.add_argument('--height', type=int, default=512, help='camera height') 22 | parser.add_argument('--cameraheight', type=float, default=50, help='camera pose generator default height') 23 | parser.add_argument('--camgenoverlap', type=float, default=0, help='camera pose generator default overlap rate') 24 | args = parser.parse_args() 25 | return args 26 | 27 | 28 | def setFOV(ctr, fov): 29 | if fov < math.pi: 30 | fov_deg = fov * 180 / math.pi 31 | else: 32 | fov_deg = fov 33 | cur_fovy = ctr.get_field_of_view() 34 | diff_fov = fov_deg - cur_fovy 35 | step_fov = diff_fov / 5.0 36 | ctr.change_field_of_view(step=step_fov) 37 | return ctr 38 | 39 | 40 | if __name__ == '__main__': 41 | args = parseArgs() 42 | print(args) 43 | 44 | print("Instruction") 45 | print("-----------") 46 | print(" [SPC] Record Current View") 47 | 48 | WHRatio = args.width / args.height 49 | prin_x = args.width / 2.0 50 | prin_y = args.height / 2.0 51 | 52 | K = np.array([[args.focal, 0, prin_x], 53 | [0, args.focal, prin_y], 54 | [0, 0, 1]]) 55 | invK = np.linalg.inv(K) 56 | fovy = 2.0 * math.atan2(args.height, 2.0 * args.focal) 57 | nearClipping = 0.1 58 | farClipping = 1000 59 | 60 | ### data 61 | pcd = o3d.io.read_point_cloud(args.cloud) 62 | camjson = [] 63 | 64 | if args.input_list and osp.exists(args.input_list): 65 | with open(args.input_list) as f: 66 | ondisk = json.load(f) 67 | if 'imgs' in ondisk: 68 | camjson = ondisk['imgs'] 69 | print(f'Read in {len(camjson)} virtual views.') 70 | ### Vis and Interaction 71 | fig = plt.figure() 72 | fig.canvas.set_window_title(f"Num of Virtual Views: {len(camjson)}") 73 | vis = o3d.visualization.VisualizerWithKeyCallback() 74 | vis.create_window(width=args.width + 1, height=args.height + 1) 75 | vis.add_geometry(pcd) 76 | ctr = vis.get_view_control() 77 | setFOV(ctr, fovy) 78 | ctr.set_constant_z_near(nearClipping) 79 | ctr.set_constant_z_far(farClipping) 80 | print("Set z near %.2f" % nearClipping) 81 | print("Set z far %.2f" % farClipping) 82 | print("Set field of view %.2f" % ctr.get_field_of_view()) 83 | 84 | 85 | def mkCamera(K, R, C): 86 | return {'width': args.width, 87 | 'height': args.height, 88 | 'C': [C[0], C[1], C[2]], 89 | 'K': [[K[0, 0], K[0, 1], K[0, 2]], 90 | [K[1, 0], K[1, 1], K[1, 2]], 91 | [K[2, 0], K[2, 1], K[2, 2]]], 92 | 'R': [[R[0, 0], R[0, 1], R[0, 2]], 93 | [R[1, 0], R[1, 1], R[1, 2]], 94 | [R[2, 0], R[2, 1], R[2, 2]]] 95 | } 96 | 97 | 98 | def capture_depth_and_img(vis): 99 | depth = np.asarray(vis.capture_depth_float_buffer()) 100 | # image = vis.capture_screen_float_buffer() 101 | # plt.imshow(np.asarray(image)) 102 | plt.imshow(depth) 103 | fig.canvas.set_window_title(f"Num of Virtual Views: {len(camjson)}") 104 | plt.draw() 105 | plt.pause(0.001) 106 | plt.pause(0.001) 107 | 108 | 109 | def capture_pose(vis): 110 | ctr = vis.get_view_control() 111 | camparam = ctr.convert_to_pinhole_camera_parameters() 112 | intrinsic = camparam.intrinsic.intrinsic_matrix 113 | extrinsic = camparam.extrinsic 114 | 115 | R = extrinsic[:3, :3] 116 | C = -R.T.dot(extrinsic[:3, 3]) 117 | camjson.append(mkCamera(K, R, C)) 118 | capture_depth_and_img(vis) 119 | 120 | vis.register_key_callback(ord(' '), capture_pose) 121 | vis.run() 122 | vis.destroy_window() 123 | 124 | # Output part 125 | content = json.dumps({'imgs': camjson}, indent=2) 126 | if args.output_list: 127 | with open(args.output_list, 'w') as f: 128 | f.write(content) 129 | else: 130 | print(content) 131 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_filter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Plugin libs #### 2 | set(SRCS 3 | GTFILTER_plugin.cpp 4 | RAYGTFILTER_plugin.cpp) 5 | 6 | set(HEADERS 7 | GTFILTER_plugin.h 8 | RAYGTFILTER_plugin.h) 9 | 10 | if(BUILD_SHARED_PLUGINS) 11 | add_library(FILTER_plugins SHARED ${SRCS}) 12 | target_compile_definitions(FILTER_plugins PRIVATE PLUGIN_DLL_EXPORTS) 13 | else() 14 | add_library(FILTER_plugins STATIC ${SRCS}) 15 | endif() 16 | 17 | target_include_directories(FILTER_plugins INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 18 | target_link_libraries(FILTER_plugins 19 | PUBLIC FBORender PluginInterface 20 | PRIVATE qhullcpp::qhullcpp CGAL::CGAL 21 | ${OpenCV_LIBS} pcl_io) 22 | set_target_properties(FILTER_plugins PROPERTIES 23 | PUBLIC_HEADER "${HEADERS}") 24 | 25 | install(TARGETS FILTER_plugins 26 | RUNTIME DESTINATION bin 27 | ARCHIVE DESTINATION lib 28 | LIBRARY DESTINATION lib 29 | PUBLIC_HEADER DESTINATION include/plugins) 30 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_filter/GTFILTER_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef GTFILTER_PLUGIN_H 2 | #define GTFILTER_PLUGIN_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Plugin/plugininterface.h" 8 | 9 | namespace FBORender { class MultidrawFBO; }; 10 | 11 | class GTFILTER_Plugin : public PluginInterface { 12 | public: 13 | GTFILTER_Plugin(); 14 | virtual std::string getWorkerName(); 15 | virtual bool operator()(const nlohmann::json& blockJson); 16 | 17 | private: 18 | const char* WORKER_NAME = "GTFILTER"; 19 | 20 | bool exists_test(const std::string& name); 21 | bool processBlock(const nlohmann::json& blockJson); 22 | }; 23 | #endif // GTFILTER_PLUGIN_H 24 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_filter/RAYGTFILTER_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGTFILTER_PLUGIN_H 2 | #define RAYGTFILTER_PLUGIN_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Plugin/plugininterface.h" 8 | 9 | struct RAYGTFILTER_Plugin_Cache; 10 | 11 | class RAYGTFILTER_Plugin : public PluginInterface { 12 | public: 13 | RAYGTFILTER_Plugin(); 14 | ~RAYGTFILTER_Plugin(); 15 | virtual std::string getWorkerName(); 16 | virtual bool operator()(const nlohmann::json &blockJson); 17 | 18 | private: 19 | const char *WORKER_NAME = "RAYGTFILTER"; 20 | std::unique_ptr cache; 21 | bool exists_test(const std::string &name); 22 | bool processBlock(const nlohmann::json &blockJson); 23 | }; 24 | #endif // RAYGTFILTER_PLUGIN_H 25 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_filter/env_setup.h: -------------------------------------------------------------------------------- 1 | #ifndef ENV_SETUP_H 2 | #define ENV_SETUP_H 3 | #include "FBORender/FBORender.h" 4 | #include 5 | 6 | static std::shared_ptr fbo; 7 | 8 | inline bool setup() { 9 | if (!fbo) { 10 | fbo.reset(new FBORender::MultidrawFBO); 11 | } 12 | FBORender::initGLContext(); 13 | FBORender::GLMakeContextCurrent(); 14 | return true; 15 | } 16 | #endif // ENV_SETUP_H 17 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Plugin libs #### 2 | set(SRCS json2pydict.cpp 3 | NETWORKVISIBILITY_plugin.cpp 4 | # O3DHPRVISIBILITY_plugin.cpp 5 | ) 6 | set(HEADERS NETWORKVISIBILITY_plugin.h 7 | # O3DHPRVISIBILITY_plugin.h 8 | ) 9 | 10 | if (BUILD_SHARED_PLUGINS) 11 | add_library(NETWORKVISIBILITY_plugin SHARED ${SRCS}) 12 | target_compile_definitions(NETWORKVISIBILITY_plugin PRIVATE PLUGIN_DLL_EXPORTS) 13 | elseif () 14 | add_library(NETWORKVISIBILITY_plugin STATIC ${SRCS}) 15 | endif () 16 | 17 | target_include_directories(NETWORKVISIBILITY_plugin INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 18 | target_link_libraries(NETWORKVISIBILITY_plugin 19 | PUBLIC PluginInterface 20 | PRIVATE pybind11::embed) 21 | set_target_properties(NETWORKVISIBILITY_plugin PROPERTIES 22 | PUBLIC_HEADER "${HEADER}") 23 | 24 | install(TARGETS NETWORKVISIBILITY_plugin 25 | RUNTIME DESTINATION bin 26 | ARCHIVE DESTINATION lib 27 | LIBRARY DESTINATION lib 28 | PUBLIC_HEADER DESTINATION include/plugins) 29 | 30 | install(FILES network_predict.py hpr_predict.py 31 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 32 | DESTINATION lib) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/NETWORKVISIBILITY_plugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS NETWORKVISIBILITY_plugin - IMPLEMENTATION 20 | // 21 | //================================================================ 22 | 23 | //== INCLUDES ==================================================== 24 | 25 | #include "NETWORKVISIBILITY_plugin.h" 26 | #include "json2pydict.h" 27 | 28 | #include "filesystem/ghc/filesystem.hpp" 29 | namespace fs = ghc::filesystem; 30 | #include 31 | #include 32 | 33 | #include 34 | namespace py = pybind11; 35 | using namespace py::literals; 36 | //== CONSTANTS =================================================== 37 | 38 | 39 | 40 | //== IMPLEMENTATION ============================================== 41 | 42 | NETWORKVISIBILITY_Plugin::NETWORKVISIBILITY_Plugin() : bridge(nullptr) { 43 | } 44 | NETWORKVISIBILITY_Plugin::~NETWORKVISIBILITY_Plugin() { 45 | } 46 | std::string NETWORKVISIBILITY_Plugin::getWorkerName() { return WORKER_NAME; } 47 | bool NETWORKVISIBILITY_Plugin::operator()(const nlohmann::json &blockJson) { 48 | return processBlock(blockJson); 49 | } 50 | 51 | bool NETWORKVISIBILITY_Plugin::initModule() { 52 | try { 53 | if (!Py_IsInitialized()) { 54 | py::initialize_interpreter(); 55 | } 56 | if (!bridge) { 57 | bridge = new py::module_; 58 | auto sys = py::module_::import("sys"); 59 | py::print("Python Configuration:"); 60 | py::print(sys.attr("executable")); 61 | py::print(sys.attr("version")); 62 | *bridge = py::module_::import("network_predict"); 63 | } 64 | } catch (py::error_already_set &e) { 65 | spdlog::error(e.what()); 66 | } 67 | return true; 68 | } 69 | bool NETWORKVISIBILITY_Plugin::releaseModule() { 70 | if (bridge) { 71 | delete bridge; 72 | } 73 | if (Py_IsInitialized()) { 74 | py::finalize_interpreter(); 75 | } 76 | return true; 77 | } 78 | bool NETWORKVISIBILITY_Plugin::ensureFolderExist(std::string path) { 79 | fs::path pp(path); 80 | if (fs::exists(pp)) { 81 | if (fs::is_directory(pp)) { 82 | return true; 83 | } else { 84 | return false; 85 | } 86 | } else { 87 | try { 88 | return fs::create_directory(pp); 89 | } catch (std::exception &e) { 90 | std::cout << e.what() << std::endl; 91 | return false; 92 | } 93 | } 94 | } 95 | 96 | bool NETWORKVISIBILITY_Plugin::processBlock(const nlohmann::json &blockJson) { 97 | // Verify block 98 | if (blockJson["Worker"].get() != WORKER_NAME) { 99 | spdlog::warn("Worker[{0}] does not match {1}.\n", blockJson["Worker"].get(), WORKER_NAME); 100 | return false; 101 | } 102 | initModule(); 103 | 104 | try { 105 | py::dict block = json2pydict::convert(blockJson); 106 | (*bridge).attr("call_plugin")(block); 107 | } catch (py::error_already_set &e) { 108 | spdlog::error(e.what()); 109 | } 110 | 111 | return true; 112 | } 113 | //---------------------------------------------------------------- 114 | 115 | nlohmann::json NETWORKVISIBILITY_Plugin::getDefaultParameters() { 116 | nlohmann::json blockJson, paramJson; 117 | 118 | return blockJson; 119 | } 120 | 121 | //================================================================ -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/NETWORKVISIBILITY_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS NETWORKVISIBILITY_plugin 20 | // 21 | // This class is 22 | // 23 | //================================================================ 24 | 25 | #ifndef VVMESH_APPS_VISIBILITY_DL_NETWORKVISIBILITY_PLUGIN_H_ 26 | #define VVMESH_APPS_VISIBILITY_DL_NETWORKVISIBILITY_PLUGIN_H_ 27 | 28 | //== INCLUDES ==================================================== 29 | #include 30 | #include 31 | #include "Plugin/plugininterface.h" 32 | 33 | //== CLASS DEFINITION ============================================ 34 | namespace pybind11 { class module_; } 35 | 36 | class NETWORKVISIBILITY_Plugin : public PluginInterface { 37 | public: 38 | NETWORKVISIBILITY_Plugin(); 39 | ~NETWORKVISIBILITY_Plugin(); 40 | virtual std::string getWorkerName(); 41 | virtual bool operator()(const nlohmann::json &blockJson); 42 | virtual nlohmann::json getDefaultParameters(); 43 | private: 44 | bool initModule(); 45 | bool releaseModule(); 46 | pybind11::module_ *bridge; 47 | const char *WORKER_NAME = "NETWORKVISIBILITY"; 48 | 49 | bool ensureFolderExist(std::string path); 50 | bool processBlock(const nlohmann::json &blockJson); 51 | }; 52 | 53 | //================================================================ 54 | 55 | 56 | 57 | #endif //VVMESH_APPS_VISIBILITY_DL_NETWORKVISIBILITY_PLUGIN_H_ 58 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/O3DHPRVISIBILITY_plugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS O3DHPRVISIBILITY_plugin - IMPLEMENTATION 20 | // 21 | //================================================================ 22 | 23 | //== INCLUDES ==================================================== 24 | 25 | #include "O3DHPRVISIBILITY_plugin.h" 26 | #include "json2pydict.h" 27 | 28 | #include "filesystem/ghc/filesystem.hpp" 29 | namespace fs = ghc::filesystem; 30 | #include 31 | #include 32 | 33 | #include 34 | namespace py = pybind11; 35 | using namespace py::literals; 36 | //== CONSTANTS =================================================== 37 | 38 | 39 | 40 | //== IMPLEMENTATION ============================================== 41 | 42 | O3DHPRVISIBILITY_Plugin::O3DHPRVISIBILITY_Plugin() : bridge(new py::module_) { 43 | py::initialize_interpreter(); 44 | auto sys = py::module_::import("sys"); 45 | py::print("Python Configuration:"); 46 | py::print(sys.attr("executable")); 47 | py::print(sys.attr("version")); 48 | 49 | *bridge = py::module_::import("hpr_predict"); 50 | } 51 | O3DHPRVISIBILITY_Plugin::~O3DHPRVISIBILITY_Plugin() { 52 | // py::finalize_interpreter(); 53 | } 54 | std::string O3DHPRVISIBILITY_Plugin::getWorkerName() { return WORKER_NAME; } 55 | bool O3DHPRVISIBILITY_Plugin::operator()(const nlohmann::json &blockJson) { 56 | return processBlock(blockJson); 57 | } 58 | bool O3DHPRVISIBILITY_Plugin::ensureFolderExist(std::string path) { 59 | fs::path pp(path); 60 | if (fs::exists(pp)) { 61 | if (fs::is_directory(pp)) { 62 | return true; 63 | } else { 64 | return false; 65 | } 66 | } else { 67 | try { 68 | return fs::create_directory(pp); 69 | } catch (std::exception &e) { 70 | std::cout << e.what() << std::endl; 71 | return false; 72 | } 73 | } 74 | } 75 | 76 | bool O3DHPRVISIBILITY_Plugin::processBlock(const nlohmann::json &blockJson) { 77 | // Verify block 78 | if (blockJson["Worker"].get() != WORKER_NAME) { 79 | spdlog::warn("Worker[{0}] does not match {1}.\n", blockJson["Worker"].get(), WORKER_NAME); 80 | return false; 81 | } 82 | py::dict block = json2pydict::convert(blockJson); 83 | (*bridge).attr("call_plugin")(block); 84 | return true; 85 | } 86 | //---------------------------------------------------------------- 87 | 88 | nlohmann::json O3DHPRVISIBILITY_Plugin::getDefaultParameters() { 89 | nlohmann::json blockJson, paramJson; 90 | 91 | return blockJson; 92 | } 93 | //================================================================ -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/O3DHPRVISIBILITY_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS O3DHPRVISIBILITY_plugin 20 | // 21 | // This class is 22 | // 23 | //================================================================ 24 | 25 | #ifndef VVMESH_APPS_VISIBILITY_NETWORK_O3DHPRVISIBILITY_PLUGIN_H_ 26 | #define VVMESH_APPS_VISIBILITY_NETWORK_O3DHPRVISIBILITY_PLUGIN_H_ 27 | 28 | //== INCLUDES ==================================================== 29 | 30 | #include 31 | #include 32 | #include "Plugin/plugininterface.h" 33 | 34 | //== CLASS DEFINITION ============================================ 35 | 36 | namespace pybind11 { class module_; } 37 | 38 | class O3DHPRVISIBILITY_Plugin : public PluginInterface { 39 | public: 40 | O3DHPRVISIBILITY_Plugin(); 41 | ~O3DHPRVISIBILITY_Plugin(); 42 | virtual std::string getWorkerName(); 43 | virtual bool operator()(const nlohmann::json &blockJson); 44 | virtual nlohmann::json getDefaultParameters(); 45 | private: 46 | pybind11::module_* bridge; 47 | const char *WORKER_NAME = "O3DHPRVISIBILITY"; 48 | 49 | bool ensureFolderExist(std::string path); 50 | bool processBlock(const nlohmann::json &blockJson); 51 | }; 52 | 53 | //================================================================ 54 | 55 | 56 | #endif //VVMESH_APPS_VISIBILITY_NETWORK_O3DHPRVISIBILITY_PLUGIN_H_ 57 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/debug/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##### Test #### 2 | # 3 | #add_executable(run_networkplugin run_networkplugin.cpp) 4 | #target_link_libraries(run_networkplugin NETWORKVISIBILITY_plugin 5 | # DELAUNAY_GC_plugin 6 | # Plugin) 7 | # 8 | ###$$$$$$$$$$$$$ example_python_call2 ############ 9 | #add_executable(example_python_call 10 | # example_call.cpp 11 | # ) 12 | #target_link_libraries(example_python_call pybind11::embed 13 | # nlohmann_json::nlohmann_json spdlog::spdlog Plugin) 14 | # 15 | ############3 example_python_call2 $#$$$$$$$$$$$ 16 | #add_executable(example_python_call2 example_call2.cpp) 17 | #target_link_libraries(example_python_call2 pybind11::embed nlohmann_json::nlohmann_json 18 | # ) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/debug/example_call.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #include "Plugin/pluginmanager.h" 17 | #include 18 | #include 19 | namespace py = pybind11; 20 | using namespace py::literals; 21 | 22 | int main() { 23 | PluginManager pm; 24 | nlohmann::json json; 25 | json["we"]=10; 26 | py::scoped_interpreter guard{}; 27 | auto sys = py::module::import("sys"); 28 | py::print("Python Configuration:"); 29 | py::print(sys.attr("executable")); 30 | py::print(sys.attr("version")); 31 | 32 | py::module torch = py::module_::import("torch"); 33 | py::object device = torch.attr("device")("cuda"); 34 | py::print(device); 35 | } 36 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/debug/example_call2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #include 17 | #include 18 | namespace py = pybind11; 19 | using namespace py::literals; 20 | 21 | int main() { 22 | py::scoped_interpreter guard{}; 23 | auto sys = py::module::import("sys"); 24 | py::print("Python Configuration:"); 25 | py::print(sys.attr("executable")); 26 | py::print(sys.attr("version")); 27 | 28 | py::module torch = py::module_::import("torch"); 29 | py::object device = torch.attr("device")("cuda"); 30 | py::print(device); 31 | } 32 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/debug/run_networkplugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #include "NETWORKVISIBILITY_plugin.h" 17 | #include "CONFLATION_DELAUNAY_GC_plugin.h" 18 | #include "DELAUNAY_GC_plugin.h" 19 | 20 | #include "Plugin/pluginmanager.h" 21 | #include 22 | int main(int argc, char **argv) { 23 | 24 | nlohmann::json json = { 25 | {"Worker", "NETWORK_VISIBILITY"}, 26 | {"Param", { 27 | {"input_rgb", 28 | "/home/sxs/GDA/ONR/ONR_DEMO_2021AU/Conflation/Dataset/Garage/AIRBORNE_LIDAR_scene_2015/AIRBORNE_LIDAR_scene_2015.ply_WORK/cam1_NET.POINT_DELAY_CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])/render/pt0.png"}, 29 | {"input_depth", 30 | "/home/sxs/GDA/ONR/ONR_DEMO_2021AU/Conflation/Dataset/Garage/AIRBORNE_LIDAR_scene_2015/AIRBORNE_LIDAR_scene_2015.ply_WORK/cam1_NET.POINT_DELAY_CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])/render/pt0.flt"}, 31 | {"input_instance", 32 | "/home/sxs/GDA/ONR/ONR_DEMO_2021AU/Conflation/Dataset/Garage/AIRBORNE_LIDAR_scene_2015/AIRBORNE_LIDAR_scene_2015.ply_WORK/cam1_NET.POINT_DELAY_CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])/render/pt0.uint"}, 33 | {"input_cam", 34 | "/home/sxs/GDA/ONR/ONR_DEMO_2021AU/Conflation/Dataset/Garage/AIRBORNE_LIDAR_scene_2015/AIRBORNE_LIDAR_scene_2015.ply_WORK/cam1_NET.POINT_DELAY_CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])/render/cam0.json"}, 35 | {"input_texmesh_rgb", ""}, 36 | {"arch", 37 | "CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])"}, 38 | {"checkpoint", 39 | "/home/sxs/GDA/iccv21_vis2mesh/visibility_learning_pytorch/checkpoints/VISDEPVIS_CascadePPP_epoch30.pth"}, 40 | {"output_mask", 41 | "/home/sxs/GDA/ONR/ONR_DEMO_2021AU/Conflation/Dataset/Garage/AIRBORNE_LIDAR_scene_2015/AIRBORNE_LIDAR_scene_2015.ply_WORK/cam1_NET.POINT_DELAY_CascadeNet(['PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=2)', 'PartialConvUNet(input_channels=3)'])/conf/conf0.png"} 42 | } 43 | } 44 | }; 45 | CONFLATION_DELAUNAY_GC_Plugin p1; 46 | DELAUNAY_GC_Plugin p2; 47 | NETWORKVISIBILITY_Plugin plugin; 48 | plugin(json); 49 | PluginManager pm; 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/hpr_predict.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import argparse 3 | import json 4 | import sys 5 | 6 | from PIL import Image 7 | from tqdm import tqdm 8 | import numpy as np 9 | 10 | import open3d as o3d 11 | from utils.dataset_util import * 12 | 13 | ######## Hidden Point Removal ###################################### 14 | def hpr(camK, input, input_mask, param): 15 | dmax = input.max() 16 | ptsImage = unprojImage(input, {'K': camK}) 17 | grid_valid_mask = input_mask > 0 18 | camPts = ptsImage[:, grid_valid_mask] 19 | 20 | pcd = o3d.geometry.PointCloud() 21 | pcd.points = o3d.utility.Vector3dVector(camPts.T) 22 | # HPR 23 | mesh, inlier = pcd.hidden_point_removal(np.array([0, 0, 0]), dmax * (10 ** param)) 24 | label = np.zeros(camPts.shape[1]) 25 | label[inlier] = 1 26 | labelmap = np.zeros(input.shape) 27 | labelmap[grid_valid_mask] = label 28 | return labelmap 29 | 30 | def call_plugin(blockJson): 31 | if blockJson['Worker'] != "O3DHPRVISIBILITY": 32 | return 33 | paramJson = blockJson['Param'] 34 | input_depth = paramJson['input_depth'] 35 | input_cam = paramJson['input_cam'] 36 | radius_exp = paramJson['radius_exp'] 37 | output_mask = paramJson['output_mask'] 38 | 39 | rawdep = readFlt(input_depth) 40 | validmask = (rawdep>0).astype(np.float32) 41 | rawcam = readCam(input_cam) 42 | 43 | inliermap = hpr(np.asarray(rawcam['K']), rawdep, validmask, radius_exp) 44 | 45 | outliermap = (1-inliermap)*validmask 46 | outliermap *= 255 47 | 48 | maskImg = Image.fromarray(outliermap.astype(np.uint8)) 49 | maskImg.save(output_mask) 50 | print(f'Output: {output_mask}') 51 | 52 | if __name__ == '__main__': 53 | argparse = argparse.ArgumentParser() 54 | argparse.add_argument('input_json',type=str) 55 | args = argparse.parse_args() 56 | INPUT_JSON = args.input_json 57 | 58 | with open(INPUT_JSON,'r') as f: 59 | rootJson = json.load(f) 60 | if not isinstance(rootJson,list): 61 | rootJson = [rootJson] 62 | 63 | for blockJson in tqdm(rootJson): 64 | call_plugin(blockJson) 65 | 66 | sys.exit(0) 67 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/json2pydict.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #include "json2pydict.h" 17 | #include 18 | 19 | namespace json2pydict { 20 | pybind11::object convertBool(const nlohmann::json &_json) { return pybind11::bool_(_json.get()); } 21 | pybind11::object convertNumeric(const nlohmann::json &_json) { return pybind11::float_(_json.get()); } 22 | pybind11::object convertIntegral(const nlohmann::json &_json) { return pybind11::int_(_json.get()); } 23 | pybind11::object convertString(const nlohmann::json &_json) { return pybind11::str(_json.get()); } 24 | 25 | pybind11::object convert(const nlohmann::json &_json) { 26 | if (_json.is_array()) return convertArray(_json); 27 | else if (_json.is_object()) return convertObject(_json); 28 | else if (_json.is_boolean()) return convertBool(_json); 29 | else if (_json.is_number_float()) return convertNumeric(_json); 30 | else if (_json.is_number_integer()) return convertIntegral(_json); 31 | else if (_json.is_string()) return convertString(_json); 32 | else { 33 | spdlog::error("Unknown type: {0}", _json.type()); 34 | return pybind11::str("Error"); 35 | } 36 | } 37 | 38 | pybind11::object convertObject(const nlohmann::json &_json) { 39 | pybind11::dict dict; 40 | for (auto it = _json.begin(); it != _json.end(); ++it) { 41 | dict[it.key().c_str()] = convert(it.value()); 42 | } 43 | return dict; 44 | } 45 | 46 | pybind11::object convertArray(const nlohmann::json &_json) { 47 | pybind11::list list; 48 | for (auto it = _json.begin(), end = _json.end(); it != end; ++it) { 49 | list.append(convert(*it)); 50 | } 51 | return list; 52 | } 53 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/json2pydict.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #ifndef VVMESH_APPS_VISIBILITY_NETWORK_JSON2PYDICT_H_ 17 | #define VVMESH_APPS_VISIBILITY_NETWORK_JSON2PYDICT_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace json2pydict { 23 | pybind11::object convertArray(const nlohmann::json &_json); 24 | pybind11::object convertObject(const nlohmann::json &_json); 25 | pybind11::object convertBool(const nlohmann::json &_json); 26 | pybind11::object convertNumeric(const nlohmann::json &_json); 27 | pybind11::object convertIntegral(const nlohmann::json &_json); 28 | pybind11::object convertString(const nlohmann::json &_json); 29 | pybind11::object convert(const nlohmann::json &_json); 30 | } 31 | 32 | #endif //VVMESH_APPS_VISIBILITY_NETWORK_JSON2PYDICT_H_ 33 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/visibility_network/network_predict.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import argparse 3 | import json 4 | import sys 5 | 6 | from PIL import Image 7 | import tqdm 8 | import numpy as np 9 | from model import * 10 | from utils.visdataset import * 11 | from utils.dataset_util import * 12 | 13 | import torch 14 | 15 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 16 | 17 | ################ 18 | class NetworkHolder: 19 | def __init__(self): 20 | self.net_ = None 21 | self.arch_ = None 22 | self.checkpoint_ = None 23 | 24 | def GetNetwork(self, arch, checkpoint): 25 | if self.net_!=None and self.arch_ == arch and self.checkpoint_ == checkpoint: 26 | return self.net_ 27 | # reinitialize network 28 | self.net_=None 29 | try: 30 | self.net_ = eval(arch) 31 | except Exception as e: 32 | print(f'Init Network failed:\n {e}') 33 | return None 34 | assert (self.net_ is not None) 35 | self.net_.to(device=device) 36 | self.net_.load_state_dict(torch.load(checkpoint, map_location=device)) 37 | self.arch_=arch 38 | self.checkpoint_ = checkpoint 39 | print(f'Init {arch} with {checkpoint}') 40 | return self.net_ 41 | 42 | @staticmethod 43 | def processInput(pointdep, bgmask=False, invert=True, normalize=True, normalize_znear=False): 44 | 45 | dmax = pointdep.max() 46 | pointvalid = (pointdep > -1).astype(np.float32) 47 | pointdep[pointdep < 0] = dmax 48 | dmin = pointdep.min() 49 | if invert: 50 | pointdep = dmax - pointdep 51 | 52 | if normalize: 53 | if normalize_znear: 54 | pointdep = pointdep / (dmax-dmin) 55 | else: 56 | pointdep = pointdep / dmax 57 | 58 | return pointdep, pointvalid 59 | 60 | @staticmethod 61 | def predict_img(net, input, input_mask, device): 62 | net.eval() 63 | input = torch.from_numpy(input).reshape(1,1,*input.shape).to(device=device,dtype=torch.float32) 64 | input_mask = torch.from_numpy(input_mask).reshape(1,1,*input_mask.shape).to(device=device,dtype=torch.float32) 65 | with torch.no_grad(): 66 | output = net(torch.cat([input,input_mask],1)) 67 | probs = torch.sigmoid(output) * input_mask 68 | full_mask = probs.squeeze().cpu().numpy() 69 | 70 | return full_mask 71 | 72 | nh = NetworkHolder() 73 | def call_plugin(blockJson): 74 | if blockJson['Worker'] != "NETWORKVISIBILITY": 75 | return 76 | paramJson = blockJson['Param'] 77 | input_depth = paramJson['input_depth'] 78 | arch = paramJson['arch'] 79 | checkpoint = paramJson['checkpoint'] 80 | output_mask = paramJson['output_mask'] 81 | 82 | # Get network 83 | net = nh.GetNetwork(arch, checkpoint) 84 | rawdep = readFlt(input_depth) 85 | ptdep, ptvalid = nh.processInput(rawdep,invert=True,normalize=True, normalize_znear=False) 86 | 87 | pred = nh.predict_img(net=net, input=ptdep, input_mask=ptvalid, device=device) 88 | pred = 255*pred 89 | 90 | maskImg = Image.fromarray(pred.astype(np.uint8)) 91 | maskImg.save(output_mask) 92 | print(f'Output: {output_mask}') 93 | 94 | if __name__ == '__main__': 95 | print(f'Using device {device}') 96 | 97 | argparse = argparse.ArgumentParser() 98 | argparse.add_argument('input_json',type=str) 99 | args = argparse.parse_args() 100 | INPUT_JSON = args.input_json 101 | 102 | with open(INPUT_JSON,'r') as f: 103 | rootJson = json.load(f) 104 | if not isinstance(rootJson,list): 105 | rootJson = [rootJson] 106 | 107 | for blockJson in tqdm(rootJson): 108 | call_plugin(blockJson) 109 | 110 | sys.exit(0) 111 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/vvtool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(TIFF REQUIRED) 2 | add_executable(vvtool main.cpp) 3 | target_link_libraries(vvtool 4 | Plugin 5 | FILTER_plugins 6 | GLRENDER_plugin 7 | CLOUD_BUNDLE_plugin 8 | # DELAUNAY_GC_plugin 9 | NETWORKVISIBILITY_plugin 10 | ${PCL_LIBRARIES} 11 | ${TIFF_LIBRARIES} 12 | cxxopts::cxxopts 13 | ) 14 | 15 | #pybind11_add_module(pyvvtool pybind11/vvtool_pybind11.cpp) 16 | #target_link_libraries(pyvvtool PRIVATE 17 | # Plugin 18 | # FILTER_plugins 19 | # GLRENDER_plugin 20 | # CLOUD_BUNDLE_plugin 21 | # DELAUNAY_GC_plugin 22 | # spdlog::spdlog 23 | # ) 24 | 25 | install(TARGETS vvtool 26 | RUNTIME DESTINATION bin 27 | ARCHIVE DESTINATION lib 28 | LIBRARY DESTINATION lib 29 | PUBLIC_HEADER DESTINATION include) 30 | 31 | #install(TARGETS pyvvtool 32 | # RUNTIME DESTINATION bin 33 | # ARCHIVE DESTINATION lib 34 | # LIBRARY DESTINATION lib 35 | # PUBLIC_HEADER DESTINATION include) -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/vvtool/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "FBORender/FBORender.h" 4 | 5 | #include 6 | #include 7 | 8 | #include "Plugin/builtin_plugins.h" 9 | #include "Plugin/pluginmanager.h" 10 | #include "GLRENDER_plugin.h" 11 | // #include "WWZBFILTER_plugin.h" 12 | // #include "WAPPZBFILTER_plugin.h" 13 | // #include "CONFLATION_DELAUNAY_GC_plugin.h" 14 | // #include "HPRFILTER_plugin.h" 15 | #include "GTFILTER_plugin.h" 16 | #include "RAYGTFILTER_plugin.h" 17 | #include "CLOUD_BUNDLE_plugin.h" 18 | // #include "DELAUNAY_GC_plugin.h" 19 | #include "NETWORKVISIBILITY_plugin.h" 20 | //#include "O3DHPRVISIBILITY_plugin.h" 21 | 22 | #include 23 | #include 24 | 25 | static std::shared_ptr fbo; 26 | 27 | inline bool setup() { 28 | if (!fbo) { 29 | fbo.reset(new FBORender::MultidrawFBO); 30 | } 31 | if (!FBORender::initGLContext()) 32 | return false; 33 | if (!FBORender::GLMakeContextCurrent()) 34 | return false; 35 | return true; 36 | } 37 | cxxopts::Options parseOptions() { 38 | cxxopts::Options options("vvtool", "virtual view toolbox."); 39 | options.add_options() 40 | ("i,input_json", "Input command file.json", cxxopts::value()->default_value("")) 41 | ("l,list", "List all available plugins.") 42 | ("w,write", "Write example command to file.", cxxopts::value()->implicit_value("example.json")) 43 | ("h,help", "Print usage of program") 44 | ("q,query", "Query usage or plugin.", cxxopts::value>()); 45 | options.parse_positional("input_json"); 46 | options.positional_help("command_file.json"); 47 | return options; 48 | } 49 | PluginManager pm; 50 | std::pair registerAllPlugins() { 51 | uint32_t result; 52 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 53 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 54 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 55 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 56 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 57 | result += pm.registerPlugin(std::make_shared(fbo)) ? 1 : 1 << 16; 58 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 59 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 60 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 61 | result += pm.registerPlugin(std::make_shared()) ? 1 : 1 << 16; 62 | 63 | return std::make_pair((int) (result & 0x0000FFFF), result >> 16); 64 | } 65 | 66 | int main(int argc, char **argv) { 67 | // Initialization 68 | spdlog::set_level(spdlog::level::info); 69 | if (!setup()) { 70 | spdlog::error("GL environment setup failed."); 71 | return EXIT_FAILURE; 72 | } 73 | auto regresult = registerAllPlugins(); 74 | spdlog::info("Plugins registered: {0} successed {1} failed ", regresult.first, regresult.second); 75 | // Cmd options processing 76 | auto options = parseOptions(); 77 | auto result = options.parse(argc, argv); 78 | if (result.count("help")) { 79 | std::cout << options.help() << std::endl; 80 | std::cout << "List of Available Plugins" << pm.statusPlugins() << std::endl; 81 | exit(0); 82 | } 83 | if (result.count("query")) { 84 | auto querynames = result["query"].as>(); 85 | nlohmann::json helpinfo; 86 | for (auto &queryname: querynames) { 87 | helpinfo.push_back(pm.helpPlugin(queryname)); 88 | } 89 | std::cout << helpinfo; 90 | if (result.count("write")) { 91 | std::string outputpath = result["write"].as(); 92 | std::ofstream ofs(outputpath); 93 | ofs << helpinfo; 94 | spdlog::info("Query result has been written into {0}", outputpath); 95 | } 96 | exit(0); 97 | } 98 | if (result.count("list")) { 99 | std::cout << "List of Available Plugins" << pm.statusPlugins() << std::endl; 100 | exit(0); 101 | } 102 | 103 | std::string input_param_path = result["input_json"].as(); 104 | if (input_param_path.empty()) { 105 | std::cout << options.help() << std::endl; 106 | exit(0); 107 | } 108 | 109 | nlohmann::json rootJson; 110 | { 111 | std::ifstream ifs(input_param_path); 112 | if (!ifs.is_open()) { 113 | spdlog::error("Open file {0} failed", input_param_path); 114 | exit(0); 115 | } 116 | ifs >> rootJson; 117 | ifs.close(); 118 | } 119 | // Input commands processing 120 | spdlog::info("Input Json: {0}", input_param_path); 121 | spdlog::info("=== Initializing Plugins ==="); 122 | 123 | if (rootJson.is_array()) { 124 | int cnt = rootJson.size(); 125 | spdlog::info("=== Input Process Units({0}) ===", cnt); 126 | 127 | int i = 0; 128 | for (auto &j: rootJson) { 129 | spdlog::info("=== Processing {0}/{1} ===", ++i, cnt); 130 | pm.callPlugin(j); 131 | }; 132 | } else { 133 | spdlog::info("=== Input Process Units(1) ==="); 134 | pm.callPlugin(rootJson); 135 | } 136 | 137 | spdlog::info("=== Process Done ==="); 138 | return 0; 139 | } 140 | -------------------------------------------------------------------------------- /tools/vvmesh_src/apps/vvtool/pybind11/vvtool_pybind11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | namespace py = pybind11; 8 | 9 | #include "FBORender/FBORender.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "Plugin/pluginmanager.h" 16 | #include "GLRENDER_plugin.h" 17 | #include "WWZBFILTER_plugin.h" 18 | #include "WAPPZBFILTER_plugin.h" 19 | #include "HPRFILTER_plugin.h" 20 | #include "GTFILTER_plugin.h" 21 | #include "CLOUD_BUNDLE_plugin.h" 22 | #include "DELAUNAY_GC_plugin.h" 23 | 24 | static std::shared_ptr fbo; 25 | static PluginManager pm; 26 | 27 | bool setupFBO() { 28 | if (!fbo) { 29 | fbo.reset(new FBORender::MultidrawFBO); 30 | } 31 | FBORender::initGLContext(); 32 | FBORender::GLMakeContextCurrent(); 33 | return true; 34 | } 35 | 36 | int initModule() { 37 | if (!setupFBO()) { 38 | fprintf(stderr, "GL environment setup failed.\n"); 39 | return EXIT_FAILURE; 40 | } 41 | pm.registerPlugin(std::make_shared(fbo)); 42 | pm.registerPlugin(std::make_shared(fbo)); 43 | pm.registerPlugin(std::make_shared(fbo)); 44 | pm.registerPlugin(std::make_shared()); 45 | pm.registerPlugin(std::make_shared()); 46 | pm.registerPlugin(std::make_shared()); 47 | pm.registerPlugin(std::make_shared()); 48 | return EXIT_SUCCESS; 49 | } 50 | 51 | int execute_json_file(std::string filepath) { 52 | std::string input_param_path = filepath; 53 | if (input_param_path.empty()) { 54 | return EXIT_FAILURE; 55 | } 56 | 57 | nlohmann::json rootJson; 58 | { 59 | std::ifstream ifs(input_param_path, std::ifstream::binary); 60 | ifs >> rootJson; 61 | ifs.close(); 62 | } 63 | 64 | printf("=== Input JSON: %s\n", input_param_path.c_str()); 65 | printf("=== Initializing Plugins ===\n"); 66 | 67 | if (rootJson.is_array()) { 68 | int cnt = rootJson.size(); 69 | printf("=== Input Process Units(%d) ===\n", cnt); 70 | int i = 0; 71 | for (auto &j : rootJson) { 72 | printf("=== Processing %d/%d ===\n", i + 1, cnt); 73 | pm.callPlugin(j); 74 | }; 75 | } else { 76 | printf("=== Input Process Units(1) ==="); 77 | pm.callPlugin(rootJson); 78 | } 79 | 80 | printf("=== Process Done ===\n"); 81 | return EXIT_SUCCESS; 82 | } 83 | 84 | int execute_json_string(std::string content) { 85 | nlohmann::json rootJson; 86 | 87 | 88 | bool parsingSuccessful = reader.parse(content.c_str(), rootJson); //parse process 89 | if (!parsingSuccessful) { 90 | std::cerr << "Failed to parse" << reader.getFormattedErrorMessages(); 91 | return EXIT_FAILURE; 92 | } 93 | 94 | printf("=== Input JSON from String\n"); 95 | printf("=== Initializing Plugins ===\n"); 96 | 97 | if (rootJson.is_array()) { 98 | int cnt = rootJson.size(); 99 | printf("=== Input Process Units(%d) ===\n", cnt); 100 | int i = 0; 101 | for (auto &j : rootJson) { 102 | printf("=== Processing %d/%d ===\n", i + 1, cnt); 103 | pm.callPlugin(j); 104 | }; 105 | } else { 106 | printf("=== Input Process Units(1) ==="); 107 | pm.callPlugin(rootJson); 108 | } 109 | 110 | printf("=== Process Done ===\n"); 111 | return EXIT_SUCCESS; 112 | } 113 | 114 | PYBIND11_MODULE(pyvvtool, m) { 115 | m.doc() = "Virtual view reconstruction tools python module"; 116 | m.def("execute_json_file", &execute_json_file); 117 | m.def("execute_json_string", &execute_json_string); 118 | initModule(); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/BuildExternalDeps.cmake: -------------------------------------------------------------------------------- 1 | ## System Dependencies 2 | if (UNIX) 3 | find_package(CGAL REQUIRED) 4 | find_package(OpenCV REQUIRED) 5 | find_package(GLEW REQUIRED) 6 | find_package(glfw3 REQUIRED) 7 | else () 8 | endif () 9 | find_package(PCL REQUIRED COMPONENTS common io octree search filters segmentation) 10 | ################ 11 | ## Conan.io 12 | ################ 13 | # Download automatically, you can also just copy the conan.cmake file 14 | if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") 15 | message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") 16 | file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake" 17 | "${CMAKE_BINARY_DIR}/conan.cmake") 18 | endif () 19 | 20 | include(${CMAKE_BINARY_DIR}/conan.cmake) 21 | 22 | conan_cmake_configure( 23 | REQUIRES zstd/1.5.0 24 | zlib/1.2.11 25 | doctest/2.4.6 26 | pybind11/2.6.2 27 | jsoncpp/1.9.4 28 | nlohmann_json/3.10.2 29 | eigen/3.3.9 30 | # boost/1.71.0 31 | cxxopts/2.2.1 32 | # glew/2.1.0 33 | # glfw/3.3.2 34 | glm/0.9.9.8 35 | # opencv/3.4.12 36 | tinyply/2.3.2 37 | qhullcpp/8.0.2@sxsong1207/stable 38 | # cgal/5.0.3 39 | openmesh/8.1 40 | openvolumemesh/2.1@sxsong1207/stable 41 | fmt/8.0.1 42 | spdlog/1.9.2 43 | GENERATORS cmake_find_package) 44 | 45 | conan_cmake_autodetect(settings) 46 | 47 | conan_cmake_install(PATH_OR_REFERENCE . 48 | BUILD missing 49 | REMOTE conancenter 50 | SETTINGS ${settings}) 51 | 52 | find_package(glm 0.9.9.8 EXACT REQUIRED) 53 | find_package(tinyply 2.3.2 EXACT REQUIRED) 54 | find_package(qhullcpp 8.0.2 EXACT REQUIRED) 55 | find_package(doctest 2.4.6 EXACT) 56 | find_package(jsoncpp 1.9.4 EXACT REQUIRED) 57 | find_package(nlohmann_json 3.10.2 EXACT REQUIRED) 58 | find_package(OpenMesh 8.1 EXACT REQUIRED) 59 | find_package(OpenVolumeMesh 2.1 EXACT REQUIRED) 60 | find_package(zstd 1.5.0 EXACT REQUIRED) 61 | find_package(ZLIB 1.2.11 EXACT REQUIRED) 62 | find_package(Eigen3 3.3.9 EXACT REQUIRED) 63 | # find_package(OpenCV 3.4.12 EXACT REQUIRED) 64 | # find_package(GLEW 2.1.0 EXACT REQUIRED) 65 | # find_package(glfw3 3.3.2 EXACT REQUIRED) 66 | find_package(cxxopts 2.2.1 EXACT REQUIRED) 67 | find_package(spdlog 1.9.2 EXACT REQUIRED) 68 | find_package(fmt 8.0.1 EXACT REQUIRED) 69 | find_package(pybind11 2.6.2 EXACT REQUIRED) 70 | 71 | 72 | -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/PrintProps.cmake: -------------------------------------------------------------------------------- 1 | # Get all propreties that cmake supports 2 | execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) 3 | 4 | # Convert command output into a CMake list 5 | STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") 6 | STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") 7 | 8 | function(print_properties) 9 | message ("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") 10 | endfunction(print_properties) 11 | 12 | function(print_target_properties tgt) 13 | if(NOT TARGET ${tgt}) 14 | message("There is no target named '${tgt}'") 15 | return() 16 | endif() 17 | 18 | foreach (prop ${CMAKE_PROPERTY_LIST}) 19 | string(REPLACE "" "${CMAKE_BUILD_TYPE}" prop ${prop}) 20 | # Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i 21 | if(prop STREQUAL "LOCATION" OR prop MATCHES "^LOCATION_" OR prop MATCHES "_LOCATION$") 22 | continue() 23 | endif() 24 | # message ("Checking ${prop}") 25 | get_property(propval TARGET ${tgt} PROPERTY ${prop} SET) 26 | if (propval) 27 | get_target_property(propval ${tgt} ${prop}) 28 | message ("${tgt} ${prop} = ${propval}") 29 | endif() 30 | endforeach(prop) 31 | endfunction(print_target_properties) 32 | -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/conan/pcl/README.md: -------------------------------------------------------------------------------- 1 | # conan-pcl 2 | 3 | Conan package for pcl library 4 | 5 | Modified from https://github.com/TUM-CONAN/conan-pcl -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/conan/vtk/README.md: -------------------------------------------------------------------------------- 1 | # conan-vtk 2 | Conan package for vtk library 3 | 4 | Modified based on: https://github.com/bilke/conan-vtk -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/conan/vtk/vtknetcdf_snprintf.diff: -------------------------------------------------------------------------------- 1 | diff --git a/ThirdParty/netcdf/vtknetcdf/CMakeLists.txt b/ThirdParty/netcdf/vtknetcdf/CMakeLists.txt 2 | index daf4a218b84549340006df4e2775fff27a464780..af8c272e7b82f4eee5da69d296ac9eb0bd3547f3 100644 3 | --- a/ThirdParty/netcdf/vtknetcdf/CMakeLists.txt 4 | +++ b/ThirdParty/netcdf/vtknetcdf/CMakeLists.txt 5 | @@ -143,6 +143,7 @@ check_symbol_exists("strdup" "string.h" HAVE_STRDUP) 6 | check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT) 7 | check_symbol_exists("st_blocksize" "sys/stat.h" HAVE_STRUCT_STAT_ST_BLKSIZE) 8 | check_symbol_exists("sysconf" "unistd.h" HAVE_SYSCONF) 9 | +check_symbol_exists("snprintf" "stdio.h" HAVE_SNPRINTF) 10 | 11 | set(HAVE_HDF5_H 1) 12 | check_symbol_exists("H5free_memory" "vtk_hdf5.h" HDF5_HAS_H5FREE) 13 | -------------------------------------------------------------------------------- /tools/vvmesh_src/cmake/conan/vtk/vtktiff_mangle.diff: -------------------------------------------------------------------------------- 1 | diff --git a/ThirdParty/tiff/vtktiff/libtiff/vtk_tiff_mangle.h b/ThirdParty/tiff/vtktiff/libtiff/vtk_tiff_mangle.h 2 | index ef121abeab..9f6818d7bc 100644 3 | --- a/ThirdParty/tiff/vtktiff/libtiff/vtk_tiff_mangle.h 4 | +++ b/ThirdParty/tiff/vtktiff/libtiff/vtk_tiff_mangle.h 5 | @@ -45,6 +45,7 @@ 6 | #define TIFFError vtktiff_TIFFError 7 | #define TIFFErrorExt vtktiff_TIFFErrorExt 8 | #define _TIFFerrorHandler vtktiff__TIFFerrorHandler 9 | +#define _TIFFerrorHandlerExt vtktiff__TIFFerrorHandlerExt 10 | #define _TIFFFax3fillruns vtktiff__TIFFFax3fillruns 11 | #define TIFFFaxBlackCodes vtktiff_TIFFFaxBlackCodes 12 | #define TIFFFaxBlackTable vtktiff_TIFFFaxBlackTable 13 | @@ -134,6 +135,7 @@ 14 | #define TIFFNumberOfStrips vtktiff_TIFFNumberOfStrips 15 | #define TIFFNumberOfTiles vtktiff_TIFFNumberOfTiles 16 | #define TIFFOpen vtktiff_TIFFOpen 17 | +#define TIFFOpenW vtktiff_TIFFOpenW 18 | #define TIFFPredictorCleanup vtktiff_TIFFPredictorCleanup 19 | #define TIFFPredictorInit vtktiff_TIFFPredictorInit 20 | #define _TIFFprintAscii vtktiff__TIFFprintAscii 21 | @@ -235,6 +237,7 @@ 22 | #define TIFFWarning vtktiff_TIFFWarning 23 | #define TIFFWarningExt vtktiff_TIFFWarningExt 24 | #define _TIFFwarningHandler vtktiff__TIFFwarningHandler 25 | +#define _TIFFwarningHandlerExt vtktiff__TIFFwarningHandlerExt 26 | #define TIFFWriteBufferSetup vtktiff_TIFFWriteBufferSetup 27 | #define TIFFWriteCheck vtktiff_TIFFWriteCheck 28 | #define TIFFWriteCustomDirectory vtktiff_TIFFWriteCustomDirectory 29 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(MVArchive) 2 | add_subdirectory(OBJFile) 3 | add_subdirectory(FBORender) 4 | add_subdirectory(Plugin) -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRCS multidrawfbo.cpp 2 | renderobjects.cpp 3 | util.cpp) 4 | set(HEADERS reader.h 5 | util.h 6 | renderobjects.h 7 | multidrawfbo.h 8 | dllmacro.h) 9 | 10 | add_library(FBORender STATIC ${SRCS}) 11 | target_link_libraries(FBORender 12 | PUBLIC glm::glm 13 | PRIVATE OpenGL::GL) 14 | if(UNIX) 15 | target_link_libraries(FBORender PRIVATE OpenGL::EGL m GLEW::GLEW glfw) 16 | else() 17 | target_link_libraries(FBORender PRIVATE unofficial::angle::libEGL GLEW::GLEW glfw) 18 | endif() 19 | set_target_properties(FBORender PROPERTIES 20 | PUBLIC_HEADER "${HEADERS}") 21 | target_compile_definitions(FBORender PRIVATE FBORENDER_DLL_EXPORTS) 22 | 23 | function(make_includable input_file output_file) 24 | if(input_file IS_NEWER_THAN output_file) 25 | file(READ ${input_file} content) 26 | set(delim "for_c++_include") 27 | set(content "R\"${delim}(\n${content})${delim}\"") 28 | file(WRITE ${output_file} "${content}") 29 | endif() 30 | endfunction(make_includable) 31 | 32 | # Use like 33 | make_includable(glsl/pointcloud_box.gs generated/pointcloud_box.gs) 34 | make_includable(glsl/pointcloud_diamond.gs generated/pointcloud_diamond.gs) 35 | make_includable(glsl/pointcloud_dot.gs generated/pointcloud_dot.gs) 36 | make_includable(glsl/pointcloud.fs generated/pointcloud.fs) 37 | make_includable(glsl/pointcloud_point.gs generated/pointcloud_point.gs) 38 | make_includable(glsl/pointcloud.vs generated/pointcloud.vs) 39 | make_includable(glsl/texturedtrimesh.fs generated/texturedtrimesh.fs) 40 | make_includable(glsl/texturedtrimesh.vs generated/texturedtrimesh.vs) 41 | make_includable(glsl/trimesh.vs generated/trimesh.vs) 42 | make_includable(glsl/trimesh.fs generated/trimesh.fs) 43 | make_includable(glsl/rgbtrimesh.vs generated/rgbtrimesh.vs) 44 | make_includable(glsl/rgbtrimesh.fs generated/rgbtrimesh.fs) 45 | make_includable(glsl/wwzb.cs generated/wwzb.cs) 46 | 47 | install(TARGETS FBORender 48 | RUNTIME DESTINATION bin 49 | ARCHIVE DESTINATION lib 50 | LIBRARY DESTINATION lib 51 | PUBLIC_HEADER DESTINATION include/FBORender) -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/FBORender.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | #ifndef GLOFFSCREENRENDER_SRC_FBORENDER_FBORENDER_H 22 | #define GLOFFSCREENRENDER_SRC_FBORENDER_FBORENDER_H 23 | #include "dllmacro.h" 24 | #include "util.h" 25 | #include "reader.h" 26 | #include "multidrawfbo.h" 27 | #include "renderobjects.h" 28 | #endif // GLOFFSCREENRENDER_SRC_FBORENDER_FBORENDER_H 29 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/dllmacro.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #ifndef FBORENDER_DLLMACRO_H 17 | #define FBORENDER_DLLMACRO_H 18 | #if defined(_WIN32) && !defined(NNSM_STATIC) 19 | #ifdef FBORENDER_DLL_EXPORTS 20 | #define DLL_API __declspec(dllexport) 21 | #else 22 | #define DLL_API __declspec(dllimport) 23 | #endif 24 | #else 25 | #define DLL_API 26 | #endif 27 | #endif //FBORENDER_DLLMACRO_H 28 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 vertexColorGSOutput; 3 | in float depth; 4 | flat in uint primitive_id_GS; 5 | 6 | layout(location = 0) out vec4 FragColor0; 7 | layout(location = 1) out float FragColor1; 8 | layout(location = 2) out uint FragColor2; 9 | void main() 10 | { 11 | FragColor0 = vec4(vertexColorGSOutput, 1); 12 | FragColor1 = depth; 13 | FragColor2 = primitive_id_GS; 14 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 vertexMC; 3 | in vec3 vertexColorVSInput; 4 | in float radius; 5 | in uint primitive_id; 6 | 7 | uniform mat4 MCVCMatrix; 8 | uniform mat4 VCDCMatrix; 9 | uniform mat4 MCDCMatrix; 10 | 11 | out vec3 vertexColorVSOutput; 12 | out uint primitive_id_VS; 13 | void main () 14 | { 15 | gl_Position = MCVCMatrix * vec4(vertexMC, 1.); 16 | gl_PointSize = radius; 17 | vertexColorVSOutput = vertexColorVSInput; 18 | primitive_id_VS = primitive_id; 19 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud_box.gs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(points) in ; 3 | layout(triangle_strip, max_vertices = 4) out ; 4 | 5 | in vec3 vertexColorVSOutput[]; 6 | in uint primitive_id_VS[]; 7 | uniform mat4 VCDCMatrix; 8 | 9 | out vec3 vertexColorGSOutput; 10 | out float depth; 11 | flat out uint primitive_id_GS; 12 | 13 | void main() { 14 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(-gl_in[0].gl_PointSize,-gl_in[0].gl_PointSize,0,0)); 15 | vertexColorGSOutput = vertexColorVSOutput[0]; 16 | depth = gl_in[0].gl_Position.z; 17 | primitive_id_GS = primitive_id_VS[0]; 18 | EmitVertex(); 19 | 20 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(gl_in[0].gl_PointSize,-gl_in[0].gl_PointSize,0,0)); 21 | vertexColorGSOutput = vertexColorVSOutput[0]; 22 | depth = gl_in[0].gl_Position.z; 23 | primitive_id_GS = primitive_id_VS[0]; 24 | EmitVertex(); 25 | 26 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(-gl_in[0].gl_PointSize,gl_in[0].gl_PointSize,0,0)); 27 | vertexColorGSOutput = vertexColorVSOutput[0]; 28 | depth = gl_in[0].gl_Position.z; 29 | primitive_id_GS = primitive_id_VS[0]; 30 | EmitVertex(); 31 | 32 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(gl_in[0].gl_PointSize,gl_in[0].gl_PointSize,0,0)); 33 | vertexColorGSOutput = vertexColorVSOutput[0]; 34 | depth = gl_in[0].gl_Position.z; 35 | primitive_id_GS = primitive_id_VS[0]; 36 | EmitVertex(); 37 | EndPrimitive(); 38 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud_diamond.gs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(points) in ; 3 | layout(triangle_strip, max_vertices = 4) out ; 4 | 5 | in vec3 vertexColorVSOutput[]; 6 | in uint primitive_id_VS[]; 7 | uniform mat4 VCDCMatrix; 8 | 9 | out vec3 vertexColorGSOutput; 10 | out float depth; 11 | flat out uint primitive_id_GS; 12 | 13 | void main() { 14 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(-gl_in[0].gl_PointSize,0,0,0)); 15 | vertexColorGSOutput = vertexColorVSOutput[0]; 16 | depth = gl_in[0].gl_Position.z; 17 | primitive_id_GS = primitive_id_VS[0]; 18 | EmitVertex(); 19 | 20 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(0,gl_in[0].gl_PointSize,0,0)); 21 | vertexColorGSOutput = vertexColorVSOutput[0]; 22 | depth = gl_in[0].gl_Position.z; 23 | primitive_id_GS = primitive_id_VS[0]; 24 | EmitVertex(); 25 | 26 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(0,-gl_in[0].gl_PointSize,0,0)); 27 | vertexColorGSOutput = vertexColorVSOutput[0]; 28 | depth = gl_in[0].gl_Position.z; 29 | primitive_id_GS = primitive_id_VS[0]; 30 | EmitVertex(); 31 | 32 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(gl_in[0].gl_PointSize,0,0,0)); 33 | vertexColorGSOutput = vertexColorVSOutput[0]; 34 | depth = gl_in[0].gl_Position.z; 35 | primitive_id_GS = primitive_id_VS[0]; 36 | EmitVertex(); 37 | EndPrimitive(); 38 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud_dot.gs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #define MAX_VERTEX 12 3 | layout(points) in ; 4 | layout(triangle_strip, max_vertices = MAX_VERTEX) out ; 5 | 6 | const float PI = 3.1415926535897932384626433832795; 7 | const float PI_2 = 1.57079632679489661923; 8 | const float PI_4 = 0.785398163397448309616; 9 | 10 | in vec3 vertexColorVSOutput[]; 11 | in uint primitive_id_VS[]; 12 | uniform mat4 VCDCMatrix; 13 | 14 | out vec3 vertexColorGSOutput; 15 | out float depth; 16 | flat out uint primitive_id_GS; 17 | 18 | void main() { 19 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(-gl_in[0].gl_PointSize,0,0,0)); 20 | vertexColorGSOutput = vertexColorVSOutput[0]; 21 | depth = gl_in[0].gl_Position.z; 22 | primitive_id_GS = primitive_id_VS[0]; 23 | EmitVertex(); 24 | 25 | float nseg = float(MAX_VERTEX - 2) / 2.f+1; 26 | float step = PI/float(nseg); 27 | float phi = -PI_2 + step; 28 | while(phi<= (PI_2 - step)) 29 | { 30 | float x = gl_in[0].gl_PointSize * sin(phi); 31 | float y = gl_in[0].gl_PointSize * cos(phi); 32 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(x,y,0,0)); 33 | vertexColorGSOutput = vertexColorVSOutput[0]; 34 | depth = gl_in[0].gl_Position.z; 35 | primitive_id_GS = primitive_id_VS[0]; 36 | EmitVertex(); 37 | 38 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(x,-y,0,0)); 39 | vertexColorGSOutput = vertexColorVSOutput[0]; 40 | depth = gl_in[0].gl_Position.z; 41 | primitive_id_GS = primitive_id_VS[0]; 42 | EmitVertex(); 43 | 44 | phi = phi + step; 45 | } 46 | 47 | gl_Position = VCDCMatrix * (gl_in[0].gl_Position + vec4(gl_in[0].gl_PointSize,0,0,0)); 48 | vertexColorGSOutput = vertexColorVSOutput[0]; 49 | depth = gl_in[0].gl_Position.z; 50 | primitive_id_GS = primitive_id_VS[0]; 51 | EmitVertex(); 52 | EndPrimitive(); 53 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/pointcloud_point.gs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(points) in ; 3 | layout(points, max_vertices = 1) out ; 4 | 5 | in vec3 vertexColorVSOutput[]; 6 | in uint primitive_id_VS[]; 7 | uniform mat4 VCDCMatrix; 8 | 9 | out vec3 vertexColorGSOutput; 10 | out float depth; 11 | flat out uint primitive_id_GS; 12 | 13 | void main() { 14 | gl_Position = VCDCMatrix * gl_in[0].gl_Position; 15 | vertexColorGSOutput = vertexColorVSOutput[0]; 16 | depth = gl_in[0].gl_Position.z; 17 | primitive_id_GS = primitive_id_VS[0]; 18 | EmitVertex(); 19 | EndPrimitive(); 20 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/rgbtrimesh.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in float depth; 3 | in vec3 color; 4 | flat in uint primitive_id_VS; 5 | 6 | layout(location = 0) out vec4 FragColor0; 7 | layout(location = 1) out float FragColor1; 8 | layout(location = 2) out uint FragColor2; 9 | void main() 10 | { 11 | FragColor0 = vec4(color, 1); 12 | FragColor1 = depth; 13 | FragColor2 = primitive_id_VS; 14 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/rgbtrimesh.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 vertexMC; 3 | in vec3 vertexColor; 4 | in uint primitive_id; 5 | 6 | uniform mat4 MCVCMatrix; 7 | uniform mat4 VCDCMatrix; 8 | uniform mat4 MCDCMatrix; 9 | 10 | out float depth; 11 | out vec3 color; 12 | flat out uint primitive_id_VS; 13 | 14 | void main () 15 | { 16 | vec4 vertexVC = MCVCMatrix * vec4(vertexMC, 1.); 17 | depth = vertexVC.z; 18 | 19 | gl_Position = MCDCMatrix * vec4(vertexMC, 1.); 20 | 21 | primitive_id_VS = primitive_id; 22 | color = vertexColor; 23 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/texturedtrimesh.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in float depth; 3 | in vec2 fragTC; 4 | flat in uint primitive_id_VS; 5 | 6 | uniform sampler2D texImage; 7 | 8 | layout(location = 0) out vec4 FragColor0; 9 | layout(location = 1) out float FragColor1; 10 | layout(location = 2) out uint FragColor2; 11 | 12 | void main(){ 13 | FragColor0 = texture(texImage, fragTC); 14 | FragColor1 = depth; 15 | FragColor2 = primitive_id_VS; 16 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/texturedtrimesh.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 vertexMC; 3 | in vec2 vertexTC; 4 | in uint primitive_id; 5 | 6 | uniform mat4 MCVCMatrix; 7 | uniform mat4 VCDCMatrix; 8 | uniform mat4 MCDCMatrix; 9 | 10 | out vec2 fragTC; 11 | out float depth; 12 | flat out uint primitive_id_VS; 13 | 14 | void main () 15 | { 16 | vec4 vertexVC = MCVCMatrix * vec4(vertexMC, 1.); 17 | depth = vertexVC.z; 18 | 19 | gl_Position = MCDCMatrix * vec4(vertexMC, 1.); 20 | 21 | fragTC = vertexTC; 22 | primitive_id_VS = primitive_id; 23 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/trimesh.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 normalVS; 3 | in float depth; 4 | flat in uint primitive_id_VS; 5 | 6 | layout(location = 0) out vec4 FragColor0; 7 | layout(location = 1) out float FragColor1; 8 | layout(location = 2) out uint FragColor2; 9 | void main() 10 | { 11 | FragColor0 = vec4( normalVS*0.5+0.5 , 1); 12 | FragColor1 = depth; 13 | FragColor2 = primitive_id_VS; 14 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/trimesh.vs: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 vertexMC; 3 | in vec3 normalMC; 4 | in uint primitive_id; 5 | 6 | uniform mat4 MCVCMatrix; 7 | uniform mat4 VCDCMatrix; 8 | uniform mat4 MCDCMatrix; 9 | 10 | out float depth; 11 | out vec3 normalVS; 12 | flat out uint primitive_id_VS; 13 | 14 | void main () 15 | { 16 | vec4 vertexVC = MCVCMatrix * vec4(vertexMC, 1.); 17 | depth = vertexVC.z; 18 | 19 | gl_Position = MCDCMatrix * vec4(vertexMC, 1.); 20 | 21 | normalVS = normalMC; 22 | primitive_id_VS = primitive_id; 23 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/glsl/wwzb.cs: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout (local_size_x = 1, local_size_y = 1) in; 4 | 5 | /// Must use 'binding', otherwise, not works 6 | layout (rgba8, binding = 0) readonly uniform image2D inputColor; 7 | layout (r32f, binding = 1) readonly uniform image2D inputDepth; 8 | layout (r32ui, binding = 2) readonly uniform uimage2D inputID; 9 | 10 | layout (rgba8, binding = 3) writeonly uniform image2D outputColor; 11 | layout (r32f, binding = 4) writeonly uniform image2D outputDepth; 12 | layout (r32ui, binding = 5) writeonly uniform uimage2D outputID; 13 | 14 | layout(location=6) uniform int kernel_size; 15 | layout(location=7) uniform float focal; 16 | layout(location=8) uniform float angle_thres; 17 | 18 | layout(location=9) uniform uint invalid_index; 19 | layout(location=10) uniform float invalid_depth; 20 | 21 | void main(void) 22 | { 23 | // Image Dimension 24 | int width = int(gl_NumWorkGroups.x); 25 | int height = int(gl_NumWorkGroups.y); 26 | // Coordinate from batch 27 | ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy); 28 | // Input and output value of center pixel 29 | vec4 rgb = imageLoad(inputColor, pixel_coords); 30 | vec4 depth = imageLoad(inputDepth, pixel_coords); 31 | uvec4 id = imageLoad(inputID, pixel_coords); 32 | 33 | 34 | // Angle based filtering 35 | int halfkernel = int(kernel_size - 1) / 2; 36 | if (halfkernel>0 && id[0] != invalid_index) 37 | { 38 | // windows 39 | int sx = clamp(int(pixel_coords.x) - halfkernel, 0, width - 1); 40 | int ex = clamp(int(pixel_coords.x) + halfkernel, 0, width - 1); 41 | int sy = clamp(int(pixel_coords.y) - halfkernel, 0, height - 1); 42 | int ey = clamp(int(pixel_coords.y) + halfkernel, 0, height - 1); 43 | 44 | bool done = false; 45 | for (int rii = sy; rii <= ey; ++rii) { 46 | for (int cii = sx; cii <= ex; ++cii) { 47 | if (cii == pixel_coords.x && rii == pixel_coords.y) continue;// skip central pixel 48 | if (imageLoad(inputID, ivec2(cii, rii))[0] == invalid_index) continue;// skip invalid pixel 49 | 50 | vec4 depthP = imageLoad(inputDepth, ivec2(cii, rii)); 51 | float len = sqrt(pow(cii - pixel_coords.x, 2) + pow(rii - pixel_coords.y, 2)) * depth[0] / focal; 52 | float deltaD = (depth[0] - depthP[0]); 53 | double theta = atan(deltaD, len); 54 | 55 | if (theta > angle_thres) { 56 | depth[0] = invalid_depth; 57 | id[0] = invalid_index; 58 | rgb.xyz = vec3(0, 0, 0); 59 | done = true; 60 | break; 61 | } 62 | } 63 | if (done) break; 64 | } 65 | } 66 | 67 | // Write out 68 | imageStore(outputColor, pixel_coords, rgb); 69 | imageStore(outputDepth, pixel_coords, depth); 70 | imageStore(outputID, pixel_coords, id); 71 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/multidrawfbo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | 21 | #ifndef GLOFFSCREENRENDER_SRC_MULTIDRAWFBO_H 22 | #define GLOFFSCREENRENDER_SRC_MULTIDRAWFBO_H 23 | #include "dllmacro.h" 24 | #include "util.h" 25 | namespace FBORender { 26 | class DLL_API MultidrawFBO { 27 | public: 28 | enum { CHRGB = 0, CHZ = 1, CHID = 2, CHDEPTH = 3, NUM_RBOS = 4 }; 29 | 30 | MultidrawFBO(); 31 | ~MultidrawFBO(); 32 | inline GLuint fbo() { return mFBO; } 33 | inline int width() { return mWidth; } 34 | inline int height() { return mHeight; } 35 | 36 | bool resize(int width, int height); 37 | 38 | GLuint getTexID(int target, bool flt); 39 | 40 | bool getTexImage(int target, bool flt, void* data); 41 | bool setTexImage(int target, bool flt, const void* data); 42 | 43 | protected: 44 | GLuint createRGB8UTex(int width, int height); 45 | GLuint createR32FTex(int width, int height); 46 | GLuint createR32UITex(int width, int height); 47 | 48 | int mWidth, mHeight; 49 | GLuint mFBO; 50 | GLuint mRBOs[NUM_RBOS]; 51 | GLuint mTexs[NUM_RBOS]; 52 | GLuint mFltTexs[NUM_RBOS]; 53 | }; 54 | } // namespace FBORender 55 | #endif // GLOFFSCREENRENDER_SRC_MULTIDRAWFBO_H 56 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/pybind11/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/tools/vvmesh_src/src/FBORender/pybind11/__init__.py -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/pybind11/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | from setuptools.command.build_ext import build_ext 3 | import sys 4 | import setuptools 5 | 6 | __version__ = '0.1.0' 7 | 8 | 9 | class get_pybind_include(object): 10 | """Helper class to determine the pybind11 include path 11 | The purpose of this class is to postpone importing pybind11 12 | until it is actually installed, so that the ``get_include()`` 13 | method can be invoked. """ 14 | 15 | def __str__(self): 16 | import pybind11 17 | return pybind11.get_include() 18 | 19 | ext_modules = [ 20 | Extension( 21 | 'fborender', 22 | # Sort input source files to ensure bit-for-bit reproducible builds 23 | # (https://github.com/pybind/python_example/pull/53) 24 | sorted(['fborender_pybind11.cpp']), 25 | include_dirs=[ 26 | # Path to pybind11 headers 27 | get_pybind_include(), 28 | ], 29 | language='c++' 30 | ), 31 | ] 32 | 33 | 34 | # cf http://bugs.python.org/issue26689 35 | def has_flag(compiler, flagname): 36 | """Return a boolean indicating whether a flag name is supported on 37 | the specified compiler. 38 | """ 39 | import tempfile 40 | import os 41 | with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f: 42 | f.write('int main (int argc, char **argv) { return 0; }') 43 | fname = f.name 44 | try: 45 | compiler.compile([fname], extra_postargs=[flagname]) 46 | except setuptools.distutils.errors.CompileError: 47 | return False 48 | finally: 49 | try: 50 | os.remove(fname) 51 | except OSError: 52 | pass 53 | return True 54 | 55 | 56 | def cpp_flag(compiler): 57 | """Return the -std=c++[11/14/17] compiler flag. 58 | The newer version is prefered over c++11 (when it is available). 59 | """ 60 | flags = ['-std=c++17', '-std=c++14', '-std=c++11'] 61 | 62 | for flag in flags: 63 | if has_flag(compiler, flag): 64 | return flag 65 | 66 | raise RuntimeError('Unsupported compiler -- at least C++11 support ' 67 | 'is needed!') 68 | 69 | 70 | class BuildExt(build_ext): 71 | """A custom build extension for adding compiler-specific options.""" 72 | c_opts = { 73 | 'msvc': ['/EHsc'], 74 | 'unix': [], 75 | } 76 | l_opts = { 77 | 'msvc': [], 78 | 'unix': [], 79 | } 80 | 81 | if sys.platform == 'darwin': 82 | darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.7'] 83 | c_opts['unix'] += darwin_opts 84 | l_opts['unix'] += darwin_opts 85 | 86 | def build_extensions(self): 87 | ct = self.compiler.compiler_type 88 | opts = self.c_opts.get(ct, []) 89 | link_opts = self.l_opts.get(ct, []) 90 | if ct == 'unix': 91 | opts.append(cpp_flag(self.compiler)) 92 | if has_flag(self.compiler, '-fvisibility=hidden'): 93 | opts.append('-fvisibility=hidden') 94 | 95 | for ext in self.extensions: 96 | ext.define_macros = [('VERSION_INFO', '"{}"'.format(self.distribution.get_version()))] 97 | ext.extra_compile_args = opts 98 | ext.extra_link_args = link_opts 99 | build_ext.build_extensions(self) 100 | 101 | 102 | setup( 103 | name='fborender', 104 | version=__version__, 105 | author='Shaun Song', 106 | author_email='song.1634@osu.edu', 107 | url='', 108 | description='FBO Renderer and ZB based occlusion detection', 109 | long_description='', 110 | ext_modules=ext_modules, 111 | setup_requires=['pybind11>=2.5.0'], 112 | cmdclass={'build_ext': BuildExt}, 113 | zip_safe=False, 114 | ) -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/reader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | #ifndef GLOFFSCREENRENDER_READER_H 21 | #define GLOFFSCREENRENDER_READER_H 22 | 23 | #include 24 | #include 25 | namespace FBORender { 26 | union PointRecType { 27 | struct { 28 | float x; 29 | float y; 30 | float z; 31 | float r; 32 | float g; 33 | float b; 34 | float radius; 35 | }; 36 | float d[7]; 37 | }; 38 | typedef std::vector PointCloudType; 39 | 40 | inline PointCloudType readTXTPointCloud(std::string path) { 41 | std::ifstream ifs(path); 42 | PointCloudType pointcloud; 43 | while (!ifs.eof()) { 44 | float x, y, z, r, g, b, rad; 45 | ifs >> x >> y >> z >> r >> g >> b >> rad; 46 | pointcloud.emplace_back(PointRecType{x, y, z, r, g, b, rad}); 47 | } 48 | ifs.close(); 49 | return pointcloud; 50 | } 51 | 52 | union PtType { 53 | struct { 54 | float x; 55 | float y; 56 | float z; 57 | }; 58 | float d[3]; 59 | }; 60 | 61 | union CellType { 62 | struct { 63 | uint32_t i0; 64 | uint32_t i1; 65 | uint32_t i2; 66 | }; 67 | uint32_t d[3]; 68 | }; 69 | 70 | struct TriMeshType { 71 | std::vector points; 72 | std::vector cells; 73 | }; 74 | 75 | inline TriMeshType readOBJMesh(std::string path) { 76 | std::ifstream ifs(path); 77 | TriMeshType mesh; 78 | 79 | std::string line; 80 | while (std::getline(ifs, line)) { 81 | std::istringstream iss(line); 82 | std::string cmd; 83 | 84 | iss >> cmd; 85 | 86 | if (cmd == "v") { 87 | float x, y, z; 88 | iss >> x >> y >> z; 89 | mesh.points.emplace_back(PtType{x, y, z}); 90 | } else if (cmd == "f") { 91 | uint32_t i0, i1, i2; 92 | iss >> i0 >> i1 >> i2; 93 | mesh.cells.emplace_back(CellType{i0 - 1, i1 - 1, i2 - 1}); 94 | } 95 | } 96 | ifs.close(); 97 | return mesh; 98 | } 99 | } // namespace FBORender 100 | #endif // GLOFFSCREENRENDER_READER_H 101 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/FBORender/util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | #ifndef GLOFFSCREENRENDER_UTIL_H 21 | #define GLOFFSCREENRENDER_UTIL_H 22 | #include "dllmacro.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | namespace FBORender { 29 | DLL_API std::string _GetModuleDirPath(); 30 | 31 | DLL_API std::string load_text(std::string path); 32 | 33 | DLL_API int initGLContext(); 34 | 35 | DLL_API int GLMakeContextCurrent(); 36 | 37 | DLL_API void flipY(GLsizei width, GLsizei height, GLenum format, GLenum type, 38 | void *data); 39 | 40 | DLL_API void glReadPixelsFlipY(GLint x, GLint y, GLsizei width, GLsizei height, 41 | GLenum format, GLenum type, void *data); 42 | 43 | DLL_API void cvMatrix2glMatrix(const Eigen::Matrix &R_comp, 44 | const Eigen::Matrix &C_comp, 45 | const Eigen::Matrix &K_comp, 46 | const int imageWidth, const int imageHeight, 47 | glm::mat4 &mvMat, glm::mat4 &projMat, double near = 1, 48 | double far = 500); 49 | } // namespace FBORender 50 | 51 | #endif // GLOFFSCREENRENDER_UTIL_H 52 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/ARInterface.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _USE_OPENCV 2 | #include 3 | #endif 4 | #include "ARInterface.h" 5 | #include "ARInterface_impl.hpp" 6 | template DLL_API bool MVSA::MVArchive::SerializeSave( 7 | const MVSA::Interface &, const std::string &, int, uint32_t); 8 | 9 | template DLL_API bool MVSA::MVArchive::SerializeLoad( 10 | MVSA::Interface &, 11 | const std::string &, 12 | int* , uint32_t *); 13 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRCS ARInterface.cpp 2 | zstdstream/zstdstream.cpp) 3 | set(HEADERS dllmacro.h 4 | ARInterface.h 5 | ARInterface_impl.hpp) 6 | 7 | add_library(MVArchive STATIC ${SRCS}) 8 | target_link_libraries(MVArchive PRIVATE ${ZLIB_LIBRARIES} ${zstd_LIBRARIES} ${OpenCV_LIBS} OpenMP::OpenMP_CXX) 9 | set_target_properties(MVArchive PROPERTIES 10 | PUBLIC_HEADER "${HEADERS}") 11 | target_compile_definitions(MVArchive PRIVATE ARCHIVE_DLL_EXPORTS) 12 | 13 | # add_subdirectory(pybind11) 14 | 15 | install(TARGETS MVArchive 16 | RUNTIME DESTINATION bin 17 | ARCHIVE DESTINATION lib 18 | LIBRARY DESTINATION lib 19 | PUBLIC_HEADER DESTINATION include/MVArchive) 20 | 21 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/dllmacro.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #ifndef ARCHIVE_DLLMACRO_H 17 | #define ARCHIVE_DLLMACRO_H 18 | #if defined(_WIN32) && !defined(NNSM_STATIC) 19 | #ifdef ARCHIVE_DLL_EXPORTS 20 | #define DLL_API __declspec(dllexport) 21 | #else 22 | #define DLL_API __declspec(dllimport) 23 | #endif 24 | #else 25 | #define DLL_API 26 | #endif 27 | #endif //ARCHIVE_DLLMACRO_H 28 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/gzstream/README: -------------------------------------------------------------------------------- 1 | 2 | gzstream 3 | C++ iostream classes wrapping the zlib compression library. 4 | =========================================================================== 5 | 6 | See index.html for documentation and installation instructions. 7 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/gzstream/version: -------------------------------------------------------------------------------- 1 | 1.5 (08 Jan 2003) 2 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/pybind11/ARInterface_pybind11_scene.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS ARInterface_pybind11_scene 20 | // 21 | // This class is 22 | // 23 | //================================================================ 24 | 25 | #ifndef VVMESH_SRC_ARCHIVE_PYBIND11_ARINTERFACE_PYBIND11_SCENE_H_ 26 | #define VVMESH_SRC_ARCHIVE_PYBIND11_ARINTERFACE_PYBIND11_SCENE_H_ 27 | 28 | //== INCLUDES ==================================================== 29 | #include "MVArchive/ARInterface.h" 30 | 31 | //== CLASS DEFINITION ============================================ 32 | namespace pybind11 { 33 | class Scene : public MVSA::Interface { 34 | public: 35 | Scene(); 36 | Scene(const std::string &filename); 37 | bool load(const std::string &filename); 38 | bool save(const std::string &filename, int format = MVSA::ArchiveFormat::STDIO); 39 | void info(); 40 | bool diagnose() const; 41 | void clean_unused_images(); 42 | void clean_unused_platforms_poses_cameras(); 43 | void garbage_collect(); 44 | Scene &inflate_image_confidence(float scale); 45 | Scene &append_images(const Scene &other, size_t platform_offset); 46 | Scene &append_vertices_lines(const Scene &other, size_t image_offset); 47 | Scene &append_mesh(const Scene &other); 48 | Scene &append(const Scene &other); 49 | }; 50 | } 51 | //================================================================ 52 | 53 | 54 | 55 | #endif //VVMESH_SRC_ARCHIVE_PYBIND11_ARINTERFACE_PYBIND11_SCENE_H_ 56 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/pybind11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | remove_definitions(-D_USE_OPENCV) 2 | 3 | set(SRCS ARInterface_pybind11.cpp 4 | ARInterface_pybind11_scene.cpp 5 | ARInteface_pybind11_types.cpp 6 | ../zstdstream/zstdstream.cpp) 7 | set(HEADERS ARInterface_pybind11_scene.h) 8 | pybind11_add_module(mvaformat ${SRCS}) 9 | target_include_directories(mvaformat PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 10 | target_link_libraries(mvaformat PRIVATE ${ZLIB_LIBRARIES} ${ZSTD_LIBRARIES} ${COMPRESSED_STREAMS_LIBRARIES} OpenMP::OpenMP_CXX) 11 | target_compile_definitions(mvaformat PRIVATE ARCHIVE_DLL_EXPORTS) 12 | 13 | install(TARGETS mvaformat 14 | RUNTIME DESTINATION bin 15 | ARCHIVE DESTINATION lib 16 | LIBRARY DESTINATION lib 17 | PUBLIC_HEADER DESTINATION include) -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/pybind11/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | from setuptools.command.build_ext import build_ext 3 | import sys 4 | import setuptools 5 | 6 | __version__ = '0.1.0' 7 | 8 | 9 | class GetPybindInclude(object): 10 | """Helper class to determine the pybind11 include path 11 | The purpose of this class is to postpone importing pybind11 12 | until it is actually installed, so that the ``get_include()`` 13 | method can be invoked. """ 14 | 15 | def __str__(self): 16 | import pybind11 17 | return pybind11.get_include() 18 | 19 | 20 | ext_modules = [ 21 | Extension( 22 | 'mvaformat', 23 | # Sort input source files to ensure bit-for-bit reproducible builds 24 | # (https://github.com/pybind/python_example/pull/53) 25 | sorted(['ARInterface_pybind11.cpp']), 26 | include_dirs=[ 27 | # Path to pybind11 headers 28 | '..', 29 | '../..', 30 | GetPybindInclude(), 31 | ], 32 | libraries=['z'], 33 | language='c++' 34 | ), 35 | ] 36 | 37 | 38 | # cf http://bugs.python.org/issue26689 39 | def has_flag(compiler, flagname): 40 | """Return a boolean indicating whether a flag name is supported on 41 | the specified compiler. 42 | """ 43 | import tempfile 44 | import os 45 | with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f: 46 | f.write('int main (int argc, char **argv) { return 0; }') 47 | fname = f.name 48 | try: 49 | compiler.compile([fname], extra_postargs=[flagname]) 50 | except setuptools.distutils.errors.CompileError: 51 | return False 52 | finally: 53 | try: 54 | os.remove(fname) 55 | except OSError: 56 | pass 57 | return True 58 | 59 | 60 | def cpp_flag(compiler): 61 | """Return the -std=c++[11/14/17] compiler flag. 62 | The newer version is prefered over c++11 (when it is available). 63 | """ 64 | flags = ['-std=c++17', '-std=c++14', '-std=c++11'] 65 | 66 | for flag in flags: 67 | if has_flag(compiler, flag): 68 | return flag 69 | 70 | raise RuntimeError('Unsupported compiler -- at least C++11 support ' 71 | 'is needed!') 72 | 73 | 74 | class BuildExt(build_ext): 75 | """A custom build extension for adding compiler-specific options.""" 76 | c_opts = { 77 | 'msvc': ['/EHsc'], 78 | 'unix': [], 79 | } 80 | l_opts = { 81 | 'msvc': [], 82 | 'unix': [], 83 | } 84 | 85 | if sys.platform == 'darwin': 86 | darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.7'] 87 | c_opts['unix'] += darwin_opts 88 | l_opts['unix'] += darwin_opts 89 | 90 | def build_extensions(self): 91 | ct = self.compiler.compiler_type 92 | opts = self.c_opts.get(ct, []) 93 | link_opts = self.l_opts.get(ct, []) 94 | if ct == 'unix': 95 | opts.append(cpp_flag(self.compiler)) 96 | if has_flag(self.compiler, '-fvisibility=hidden'): 97 | opts.append('-fvisibility=hidden') 98 | 99 | for ext in self.extensions: 100 | ext.define_macros = [('VERSION_INFO', '"{}"'.format(self.distribution.get_version()))] 101 | ext.extra_compile_args = opts 102 | ext.extra_link_args = link_opts 103 | build_ext.build_extensions(self) 104 | 105 | 106 | setup( 107 | name='mvaformat', 108 | version=__version__, 109 | author='Shaun Song', 110 | author_email='song.1634@osu.edu', 111 | url='', 112 | description='A python reader/writer of .mva format file.', 113 | long_description='', 114 | ext_modules=ext_modules, 115 | setup_requires=['pybind11>=2.5.0'], 116 | cmdclass={'build_ext': BuildExt}, 117 | zip_safe=False, 118 | ) 119 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/zstdstream/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-present, Facebook, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/zstdstream/circularbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #ifdef WITHOUT_POSIX 14 | #include 15 | typedef SSIZE_T ssize_t; 16 | #endif // WITHOUT_POSIX 17 | 18 | template 19 | class CircularBuffer { 20 | public: 21 | CircularBuffer(size_t capacity) : pos_(-1), size_(0), max_(capacity) { 22 | buf_ = new T[capacity]; 23 | } 24 | ~CircularBuffer() { 25 | delete[] buf_; 26 | } 27 | 28 | void push() { 29 | pos_ = (pos_ + 1) % max_; 30 | buf_[pos_] = T(); 31 | size_ = std::min(size_ + 1, max_); 32 | } 33 | void push(T const& value) { 34 | pos_ = (pos_ + 1) % max_; 35 | buf_[pos_] = value; 36 | size_ = std::min(size_ + 1, max_); 37 | } 38 | void push(T& value) { 39 | pos_ = (pos_ + 1) % max_; 40 | buf_[pos_] = value; 41 | size_ = std::min(size_ + 1, max_); 42 | } 43 | 44 | size_t size() const { 45 | return size_; 46 | } 47 | 48 | // 0: get most recent element 49 | // <0: get past elements 50 | T const& at(ssize_t pos) const { 51 | pos = (pos + pos_) % max_; 52 | while (pos < 0) { 53 | pos = max_ + pos; 54 | } 55 | return buf_[pos]; 56 | } 57 | T& at(ssize_t pos) { 58 | pos = (pos + pos_) % max_; 59 | while (pos < 0) { 60 | pos = max_ + pos; 61 | } 62 | return buf_[pos]; 63 | } 64 | 65 | private: 66 | T* buf_; 67 | /* 68 | * max_ needs to be ssize_t for the module operator in at() to work correctly 69 | * with negative positions (which looks like a nice API). _size is >= 0 but 70 | * frequently compared to _max in std::min() which demands identical types for 71 | * its arguments. 72 | */ 73 | ssize_t pos_, size_, max_; 74 | }; 75 | 76 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/MVArchive/zstdstream/zstdstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * This source code is licensed under the BSD-style license found in the 8 | * LICENSE file in the root directory of this source tree. An additional grant 9 | * of patent rights can be found in the PATENTS file in the same directory. 10 | * 11 | * STL stream classes for Zstd compression and decompression. 12 | * Partially inspired by https://github.com/mateidavid/zstr. 13 | */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // Required to access ZSTD_isFrame() 23 | #define ZSTD_STATIC_LINKING_ONLY 24 | #include 25 | 26 | #include "circularbuffer.h" 27 | 28 | namespace zstd { 29 | 30 | /** 31 | * Custom exception for zstd error codes 32 | */ 33 | class exception : public std::exception { 34 | public: 35 | explicit exception(int code); 36 | const char* what() const throw(); 37 | 38 | private: 39 | std::string msg_; 40 | }; 41 | 42 | inline size_t check(size_t code) { 43 | if (ZSTD_isError(code)) { 44 | throw exception(code); 45 | } 46 | return code; 47 | } 48 | 49 | /** 50 | * Provides stream compression functionality 51 | */ 52 | class cstream { 53 | public: 54 | static constexpr int defaultLevel = 5; 55 | 56 | cstream(); 57 | ~cstream(); 58 | 59 | size_t init(int level = defaultLevel); 60 | size_t compress(ZSTD_outBuffer* output, ZSTD_inBuffer* input); 61 | size_t flush(ZSTD_outBuffer* output); 62 | size_t end(ZSTD_outBuffer* output); 63 | 64 | private: 65 | ZSTD_CStream* cstrm_; 66 | }; 67 | 68 | /** 69 | * Provides stream decompression functionality 70 | */ 71 | class dstream { 72 | public: 73 | dstream(); 74 | ~dstream(); 75 | 76 | size_t decompress(ZSTD_outBuffer* output, ZSTD_inBuffer* input); 77 | 78 | private: 79 | ZSTD_DStream* dstrm_; 80 | }; 81 | 82 | /** 83 | * Zstd stream buffer for compression. Data is written in a single big frame. 84 | */ 85 | class ostreambuf : public std::streambuf { 86 | public: 87 | explicit ostreambuf(std::streambuf* sbuf, int level = cstream::defaultLevel); 88 | virtual ~ostreambuf(); 89 | 90 | using int_type = typename std::streambuf::int_type; 91 | virtual int_type overflow(int_type ch = traits_type::eof()); 92 | virtual int sync(); 93 | 94 | private: 95 | ssize_t compress(size_t pos); 96 | 97 | std::streambuf* sbuf_; 98 | int clevel_; 99 | cstream strm_; 100 | std::vector inbuf_; 101 | std::vector outbuf_; 102 | size_t inhint_; 103 | bool strInit_; 104 | }; 105 | 106 | /** 107 | * Zstd stream buffer for decompression. If input data is not compressed, this 108 | * stream will simply copy it. 109 | */ 110 | class istreambuf : public std::streambuf { 111 | public: 112 | explicit istreambuf(std::streambuf* sbuf); 113 | 114 | virtual std::streambuf::int_type underflow(); 115 | 116 | private: 117 | std::streambuf* sbuf_; 118 | dstream strm_; 119 | std::vector inbuf_; 120 | std::vector outbuf_; // only needed if actually compressed 121 | size_t inhint_; 122 | size_t inpos_ = 0; 123 | size_t inavail_ = 0; 124 | bool detected_ = false; 125 | bool compressed_ = false; 126 | }; 127 | 128 | // Input stream for Zstd-compressed data 129 | class istream : public std::istream { 130 | public: 131 | istream(std::streambuf* sbuf); 132 | 133 | virtual ~istream(); 134 | }; 135 | 136 | /** 137 | * Output stream for Zstd-compressed data 138 | */ 139 | class ostream : public std::ostream { 140 | public: 141 | ostream(std::streambuf* sbuf); 142 | virtual ~ostream(); 143 | }; 144 | 145 | /** 146 | * This class enables [io]fstream below to inherit from [io]stream (required for 147 | * setting a custom streambuf) while still constructing a corresponding 148 | * [io]fstream first (required for initializing the Zstd streambufs). 149 | */ 150 | template 151 | class fsholder { 152 | public: 153 | explicit fsholder( 154 | const std::string& path, 155 | std::ios_base::openmode mode = std::ios_base::out) 156 | : fs_(path, mode) {} 157 | 158 | protected: 159 | T fs_; 160 | }; 161 | 162 | /** 163 | * Output file stream that writes Zstd-compressed data 164 | */ 165 | class ofstream : private fsholder, public std::ostream { 166 | public: 167 | explicit ofstream( 168 | const std::string& path, 169 | std::ios_base::openmode mode = std::ios_base::out); 170 | virtual ~ofstream(); 171 | 172 | virtual operator bool() const; 173 | void close(); 174 | }; 175 | 176 | /** 177 | * Input file stream for Zstd-compressed data 178 | */ 179 | class ifstream : private fsholder, public std::istream { 180 | public: 181 | explicit ifstream( 182 | const std::string& path, 183 | std::ios_base::openmode mode = std::ios_base::in); 184 | 185 | virtual ~ifstream(); 186 | operator bool() const; 187 | void close(); 188 | }; 189 | 190 | } // namespace zstd 191 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/OBJFile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRCS obj.cpp) 2 | set(HEADERS obj.h) 3 | add_library(OBJFile STATIC ${SRCS}) 4 | target_link_libraries(OBJFile PRIVATE ${opencv_LIBRARIES} ${OpenCV_LIBS}) 5 | set_target_properties(OBJFile PROPERTIES 6 | PUBLIC_HEADER "${HEADERS}") 7 | 8 | install(TARGETS OBJFile 9 | RUNTIME DESTINATION bin 10 | ARCHIVE DESTINATION lib 11 | LIBRARY DESTINATION lib 12 | PUBLIC_HEADER DESTINATION include/OBJFile) 13 | 14 | # test 15 | # add_executable(test_OBJFile test/test_OBJFile.cpp) 16 | # target_link_libraries(test_OBJFile OBJFile doctest::doctest) 17 | # add_test(test_OBJFile test_OBJFile) -------------------------------------------------------------------------------- /tools/vvmesh_src/src/OBJFile/obj.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJ_H 2 | #define OBJ_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | typedef struct Point3f{ 11 | Point3f() 12 | { 13 | std::fill_n(data,3,0.f); 14 | } 15 | Point3f(float _x, float _y, float _z) 16 | { 17 | data[0]=_x; 18 | data[1]=_y; 19 | data[2]=_z; 20 | } 21 | float data[3]; 22 | float &operator[](int i) { return data[i]; } 23 | const float &operator[](int i) const { return data[i]; } 24 | float &x() { return data[0]; } 25 | const float &x() const { return data[0]; } 26 | float &y() { return data[1]; } 27 | const float &y() const { return data[1]; } 28 | float &z() { return data[2]; } 29 | const float &z() const { return data[2]; } 30 | } Point3f; 31 | 32 | typedef struct Point2f{ 33 | Point2f() 34 | { 35 | std::fill_n(data,2,0.f); 36 | } 37 | Point2f(float _x, float _y){ 38 | data[0]=_x; 39 | data[1]=_y; 40 | } 41 | float data[2]; 42 | float &operator[](int i) { return data[i]; } 43 | const float &operator[](int i) const { return data[i]; } 44 | float &x() { return data[0]; } 45 | const float &x() const { return data[0]; } 46 | float &y() { return data[1]; } 47 | const float &y() const { return data[1]; } 48 | } Point2f; 49 | 50 | class ObjModel { 51 | public: 52 | struct MaterialLib { 53 | struct Material { 54 | std::string name; 55 | std::string diffuse_name; 56 | cv::Mat diffuse_map; 57 | 58 | Material() {} 59 | Material(const std::string &_name) : name(_name) {} 60 | Material(const cv::Mat &_diffuse_map); 61 | 62 | bool LoadDiffuseMap(); 63 | }; 64 | typedef std::vector Materials; 65 | 66 | Materials materials; 67 | MaterialLib(); 68 | // Saves the material lib to a .mtl file and all textures of its materials with the given prefix name 69 | bool Save(const std::string &prefix, bool texLossless = false) const; 70 | // Loads the material lib from a .mtl file and all textures of its materials with the given file name 71 | bool Load(const std::string &fileName); 72 | }; 73 | 74 | typedef Point3f Vertex; 75 | typedef Point3f Color; 76 | typedef Point2f TexCoord; 77 | typedef Point3f Normal; 78 | 79 | typedef uint32_t Index; 80 | 81 | struct Face { 82 | Index vertices[3]; 83 | Index texcoords[3]; 84 | Index normals[3]; 85 | }; 86 | 87 | struct Group { 88 | std::string material_name; 89 | std::vector faces; 90 | }; 91 | 92 | typedef std::vector Vertices; 93 | typedef std::vector Colors; 94 | typedef std::vector TexCoords; 95 | typedef std::vector Normals; 96 | typedef std::vector Groups; 97 | 98 | protected: 99 | Vertices vertices; 100 | Colors vertex_colors; 101 | TexCoords texcoords; 102 | Normals normals; 103 | Groups groups; 104 | MaterialLib material_lib; 105 | public: 106 | ObjModel() {} 107 | 108 | // Saves the obj model to an .obj file, its material lib and the materials with the given file name 109 | bool Save(const std::string &fileName, unsigned precision = 6, bool texLossless = false) const; 110 | // Loads the obj model from an .obj file, its material lib and the materials with the given file name 111 | bool Load(const std::string &fileName); 112 | 113 | // Creates a new group with the given material name 114 | Group &AddGroup(const std::string &material_name); 115 | // Retrieves a material from the library based on its name 116 | MaterialLib::Material *GetMaterial(const std::string &name); 117 | 118 | MaterialLib &get_material_lib() { return material_lib; } 119 | Vertices &get_vertices() { return vertices; } 120 | Colors &get_vertex_colors() {return vertex_colors;} 121 | TexCoords &get_texcoords() { return texcoords; } 122 | Normals &get_normals() { return normals; } 123 | Groups &get_groups() { return groups; } 124 | }; 125 | 126 | #endif // OBJ_H -------------------------------------------------------------------------------- /tools/vvmesh_src/src/OBJFile/test/Tile_+000_+007_L17.mtl: -------------------------------------------------------------------------------- 1 | newmtl Tile_+000_+007_L17_0 2 | Ka 1 1 1 3 | Kd 1 1 1 4 | d 1 5 | Ns 0 6 | illum 1 7 | map_Kd Tile_+000_+007_L17_0.jpg 8 | newmtl Tile_+000_+007_L17_untextured 9 | Ka 0.501961 0.501961 0.501961 10 | Kd 0.501961 0.501961 0.501961 11 | d 1 12 | Ns 0 13 | illum 1 14 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/OBJFile/test/Tile_+000_+007_L17_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/tools/vvmesh_src/src/OBJFile/test/Tile_+000_+007_L17_0.jpg -------------------------------------------------------------------------------- /tools/vvmesh_src/src/OBJFile/test/test_OBJFile.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 17 | #include 18 | #include "../obj.h" 19 | 20 | TEST_CASE("rgbobj") 21 | { 22 | ObjModel obj; 23 | CHECK(obj.Load("/home/sxs/GDA/vvmesh/src/OBJFile/test/rgbmesh.obj")); 24 | CHECK_EQ(obj.get_vertices().size(), 1997); 25 | CHECK_EQ(obj.get_normals().size(), 1997); 26 | CHECK_EQ(obj.get_vertex_colors().size(), 1997); 27 | CHECK_EQ(obj.get_groups().size(), 1); 28 | CHECK_EQ(obj.get_groups()[0].faces.size(), 3867); 29 | CHECK_EQ(obj.get_texcoords().size(), 0); 30 | } 31 | 32 | TEST_CASE("bareobj") 33 | { 34 | ObjModel obj; 35 | CHECK(obj.Load("/home/sxs/GDA/vvmesh/src/OBJFile/test/mesh.obj")); 36 | CHECK_EQ(obj.get_vertices().size(), 1997); 37 | CHECK_EQ(obj.get_normals().size(), 0); 38 | CHECK_EQ(obj.get_vertex_colors().size(), 0); 39 | CHECK_EQ(obj.get_groups().size(), 1); 40 | CHECK_EQ(obj.get_groups()[0].faces.size(), 3867); 41 | CHECK_EQ(obj.get_texcoords().size(), 0); 42 | } 43 | 44 | TEST_CASE("texured obj") 45 | { 46 | ObjModel obj; 47 | CHECK(obj.Load("/home/sxs/GDA/vvmesh/src/OBJFile/test/Tile_+000_+007_L17.obj")); 48 | CHECK_EQ(obj.get_vertices().size(), 8); 49 | CHECK_EQ(obj.get_normals().size(), 0); 50 | CHECK_EQ(obj.get_vertex_colors().size(), 0); 51 | CHECK_EQ(obj.get_groups().size(), 2); 52 | CHECK_EQ(obj.get_groups()[0].faces.size(), 7); 53 | CHECK_EQ(obj.get_texcoords().size(), 8); 54 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #### Libs #### 2 | 3 | add_library(PluginInterface STATIC plugininterface.cpp) 4 | target_link_libraries(PluginInterface 5 | PUBLIC nlohmann_json::nlohmann_json spdlog::spdlog) 6 | set_target_properties(PluginInterface PROPERTIES 7 | PUBLIC_HEADER "plugininterface.h") 8 | target_compile_definitions(PluginInterface PRIVATE PLUGIN_DLL_EXPORTS) 9 | 10 | set(SRCS 11 | builtin_plugins.cpp 12 | pluginmanager.cpp 13 | preprocess_json.cpp 14 | ) 15 | set(HEADERS dllmacro.h 16 | plugininterface.h 17 | builtin_plugins.h 18 | pluginmanager.h 19 | preprocess_json.h) 20 | 21 | # Note: This must be STATIC, otherwise, python embed will have issue. 22 | add_library(Plugin STATIC ${SRCS}) 23 | target_link_libraries(Plugin 24 | PUBLIC PluginInterface nlohmann_json::nlohmann_json 25 | PRIVATE spdlog::spdlog) 26 | set_target_properties(Plugin PROPERTIES 27 | PUBLIC_HEADER "${HEADERS}") 28 | target_compile_definitions(Plugin PRIVATE PLUGIN_DLL_EXPORTS) 29 | 30 | install(TARGETS Plugin 31 | RUNTIME DESTINATION bin 32 | ARCHIVE DESTINATION lib 33 | LIBRARY DESTINATION lib 34 | PUBLIC_HEADER DESTINATION include/pluginmanager) 35 | 36 | #### Test #### 37 | add_executable(test_plugin test/test_plugin.cpp) 38 | target_link_libraries(test_plugin Plugin doctest::doctest) 39 | 40 | add_test(NAME TestPlugin COMMAND test_plugin) 41 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/builtin_plugins.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | //================================================================ 18 | // 19 | // CLASS builtin_plugins 20 | // 21 | // This class is 22 | // 23 | //================================================================ 24 | 25 | #ifndef VVMESH_SRC_PLUGIN_BUILTIN_PLUGINS_H_ 26 | #define VVMESH_SRC_PLUGIN_BUILTIN_PLUGINS_H_ 27 | 28 | //== INCLUDES ==================================================== 29 | 30 | #include "plugininterface.h" 31 | #include 32 | 33 | //== CLASS DEFINITION ============================================ 34 | class DLL_API DefEnvPlugin : public PluginInterface { 35 | public: 36 | virtual std::string getWorkerName() { return WORKER_NAME; } 37 | virtual bool operator()(const nlohmann::json &blockJson); 38 | virtual nlohmann::json getDefaultParameters(); 39 | private: 40 | const char *WORKER_NAME = "DEFENV"; 41 | }; 42 | 43 | class DLL_API DefContextPlugin : public PluginInterface { 44 | public: 45 | virtual std::string getWorkerName() { return WORKER_NAME; } 46 | virtual bool operator()(const nlohmann::json &blockJson); 47 | virtual nlohmann::json getDefaultParameters(); 48 | private: 49 | const char *WORKER_NAME = "DEFCONTEXT"; 50 | }; 51 | 52 | class DLL_API PrintPlugin : public PluginInterface { 53 | public: 54 | virtual std::string getWorkerName() { return WORKER_NAME; } 55 | virtual bool operator()(const nlohmann::json &blockJson); 56 | virtual nlohmann::json getDefaultParameters(); 57 | private: 58 | const char *WORKER_NAME = "PRINT"; 59 | }; 60 | 61 | /** 62 | * Read list file on disk using GLOB. Save them to context variable. 63 | */ 64 | class DLL_API GlobPlugin : public PluginInterface { 65 | public: 66 | virtual std::string getWorkerName() { return WORKER_NAME; } 67 | virtual bool operator()(const nlohmann::json &blockJson); 68 | virtual nlohmann::json getDefaultParameters(); 69 | private: 70 | const char *WORKER_NAME = "GLOB"; 71 | }; 72 | 73 | class DLL_API RegexReplacePlugin : public PluginInterface { 74 | public: 75 | virtual std::string getWorkerName() { return WORKER_NAME; } 76 | virtual bool operator()(const nlohmann::json &blockJson); 77 | virtual nlohmann::json getDefaultParameters(); 78 | private: 79 | bool processTask(const nlohmann::json &taskJson); 80 | const char *WORKER_NAME = "REGEX_REPLACE"; 81 | }; 82 | //================================================================ 83 | 84 | 85 | 86 | #endif //VVMESH_SRC_PLUGIN_BUILTIN_PLUGINS_H_ 87 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/dllmacro.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #ifndef PLUGIN_DLLMACRO_H 17 | #define PLUGIN_DLLMACRO_H 18 | #if defined(_WIN32) && !defined(NNSM_STATIC) 19 | #ifdef PLUGIN_DLL_EXPORTS 20 | #define DLL_API __declspec(dllexport) 21 | #else 22 | #define DLL_API __declspec(dllimport) 23 | #endif 24 | #else 25 | #define DLL_API 26 | #endif 27 | #endif //CPUNN2_DLLMACRO_H 28 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/plugininterface.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Shaun Song 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | // Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | #include "plugininterface.h" 17 | #include "pluginmanager.h" 18 | 19 | PluginInterface::PluginInterface() : pm_(nullptr) { 20 | 21 | } 22 | 23 | std::unordered_map *PluginInterface::context() { 24 | if (pm_ != nullptr) { 25 | return &(pm_->context); 26 | } 27 | return nullptr; 28 | } 29 | 30 | std::unordered_map *PluginInterface::env() { 31 | if (pm_ != nullptr) { 32 | return &(pm_->environmental_vars); 33 | } 34 | return nullptr; 35 | } 36 | 37 | void PluginInterface::setPluginManager(PluginManager *pm) { 38 | pm_ = pm; 39 | } 40 | 41 | nlohmann::json PluginInterface::getDefaultParameters() { 42 | return nlohmann::json("[" + getWorkerName() + "] Not default parameters are provided."); 43 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/plugininterface.h: -------------------------------------------------------------------------------- 1 | #ifndef PLUGININTERFACE_H 2 | #define PLUGININTERFACE_H 3 | #include "dllmacro.h" 4 | #include 5 | #include 6 | #include 7 | 8 | class PluginManager; 9 | 10 | class DLL_API PluginInterface { 11 | public: 12 | PluginInterface(); 13 | virtual std::string getWorkerName() = 0; 14 | virtual bool operator()(const nlohmann::json &blockJson) = 0; 15 | virtual nlohmann::json getDefaultParameters(); 16 | protected: 17 | std::unordered_map *context(); 18 | std::unordered_map *env(); 19 | void setPluginManager(PluginManager *pm); 20 | 21 | PluginManager *pm_; 22 | 23 | friend class PluginManager; 24 | }; 25 | #endif 26 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/pluginmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "pluginmanager.h" 2 | 3 | #include "plugininterface.h" 4 | #include "preprocess_json.h" 5 | 6 | #include 7 | 8 | PluginManager::PluginManager() {} 9 | 10 | bool PluginManager::registerPlugin(std::shared_ptr plugin) { 11 | std::string key = plugin->getWorkerName(); 12 | if (plugins_.find(key) == plugins_.end()) { 13 | // not exists 14 | plugins_[key] = plugin; 15 | plugins_[key]->setPluginManager(this); 16 | spdlog::info("Register Plugin: {0} success.", key.c_str()); 17 | return true; 18 | } else { 19 | spdlog::warn("Register Plugin: {0} failed.", key.c_str()); 20 | return false; 21 | } 22 | } 23 | 24 | bool PluginManager::callPlugin(const nlohmann::json &blockJson) { 25 | std::string queryName = blockJson.value("Worker", ""); 26 | // Make replace list from env vars 27 | std::unordered_map envreplacelist; 28 | for (auto it = environmental_vars.begin(); it != environmental_vars.end(); ++it) { 29 | envreplacelist.insert(std::make_pair("[" + it->first + "]", it->second)); 30 | } 31 | 32 | nlohmann::json processed_json = preprocess_str_json(blockJson, envreplacelist, false); 33 | processed_json = preprocess_value_json(processed_json, context); 34 | if (queryName.empty()) { 35 | spdlog::critical("Worker name is empty"); 36 | return false; 37 | } 38 | auto pPlugin = plugins_.find(queryName); 39 | if (pPlugin == plugins_.end()) { 40 | spdlog::critical("Plugin {0} not found.", queryName.c_str()); 41 | return false; 42 | } 43 | return (*pPlugin->second)(processed_json); 44 | } 45 | 46 | bool PluginManager::existPlugin(std::string queryName) { 47 | auto pPlugin = plugins_.find(queryName); 48 | return pPlugin != plugins_.end(); 49 | } 50 | 51 | nlohmann::json PluginManager::helpPlugin(std::string queryName) { 52 | nlohmann::json value; 53 | auto pPlugin = plugins_.find(queryName); 54 | if (pPlugin == plugins_.end()) { 55 | value = "Requested Plugin[" + queryName + "] have not been registered."; 56 | return value; 57 | } else { 58 | return pPlugin->second->getDefaultParameters(); 59 | } 60 | } 61 | 62 | nlohmann::json PluginManager::statusPlugins() { 63 | nlohmann::json result; 64 | for (auto &kv: plugins_) { 65 | result.push_back(kv.first); 66 | } 67 | return result; 68 | } -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/pluginmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef PLUGINMANAGER_H 2 | #define PLUGINMANAGER_H 3 | #include "dllmacro.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class PluginInterface; 10 | class DLL_API PluginManager { 11 | public: 12 | PluginManager(); 13 | bool registerPlugin(std::shared_ptr plugin); 14 | bool callPlugin(const nlohmann::json &blockJson); 15 | bool existPlugin(std::string queryName); 16 | nlohmann::json helpPlugin(std::string queryName); 17 | nlohmann::json statusPlugins(); 18 | 19 | std::unordered_map context; 20 | std::unordered_map environmental_vars; 21 | protected: 22 | std::unordered_map > plugins_; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/preprocess_json.cpp: -------------------------------------------------------------------------------- 1 | #include "preprocess_json.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | std::string regex_escape(std::string input) { 8 | const std::regex specialChars{R"([-[\]{}()*+?.,\^$|#\s])"}; 9 | return std::regex_replace(input, specialChars, R"(\$&)"); 10 | } 11 | 12 | nlohmann::json preprocess_value_json( 13 | const nlohmann::json _json, 14 | std::unordered_map kvpair) { 15 | const std::regex tag_regex("^<(.*)>$"); 16 | std::smatch matches; 17 | 18 | nlohmann::json json = _json; 19 | std::queue nodelist; 20 | nodelist.push(&json); 21 | while (!nodelist.empty()) { 22 | nlohmann::json *pnode = nodelist.front(); 23 | nodelist.pop(); 24 | for (nlohmann::json::iterator it = pnode->begin(); it != pnode->end(); ++it) { 25 | if (it->is_string()) { 26 | std::string strval = it->get(); 27 | std::string tag = ""; 28 | if (std::regex_search(strval, matches, tag_regex)) { 29 | tag = (matches.end() - 1)->str(); 30 | } 31 | auto pos = kvpair.find(tag); 32 | if (pos != kvpair.end()) 33 | (*it) = pos->second; 34 | } else if (it->is_object()) { 35 | nodelist.push(&(*it)); 36 | } else if (it->is_array()) { 37 | nodelist.push(&(*it)); 38 | } 39 | } 40 | } 41 | 42 | return json; 43 | } 44 | 45 | nlohmann::json preprocess_str_json( 46 | const nlohmann::json _json, 47 | std::unordered_map kvpair, 48 | bool regex) { 49 | // Compile to regex 50 | std::vector> regexps; 51 | for (auto &p: kvpair) { 52 | std::string sanitized = regex ? p.first : regex_escape(p.first); 53 | regexps.emplace_back(std::make_pair(std::regex(sanitized), p.second)); 54 | } 55 | 56 | nlohmann::json json = _json; 57 | std::queue nodelist; 58 | nodelist.push(&json); 59 | while (!nodelist.empty()) { 60 | nlohmann::json *pnode = nodelist.front(); 61 | nodelist.pop(); 62 | for (nlohmann::json::iterator it = pnode->begin(); it != pnode->end(); ++it) { 63 | if (it->is_string()) { 64 | std::string strval = it->get(); 65 | for (auto &rp: regexps) { 66 | strval = std::regex_replace(strval, rp.first, rp.second); 67 | } 68 | (*it) = strval; 69 | } else if (it->is_object()) { 70 | nodelist.push(&(*it)); 71 | } else if (it->is_array()) { 72 | nodelist.push(&(*it)); 73 | } 74 | } 75 | } 76 | 77 | return json; 78 | } 79 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/Plugin/preprocess_json.h: -------------------------------------------------------------------------------- 1 | #ifndef PREPROCESS_JSON_H 2 | #define PREPROCESS_JSON_H 3 | 4 | #include "dllmacro.h" 5 | #include 6 | #include 7 | #include 8 | DLL_API nlohmann::json preprocess_value_json( 9 | const nlohmann::json _json, 10 | std::unordered_map kvpair); 11 | 12 | DLL_API nlohmann::json preprocess_str_json( 13 | const nlohmann::json _json, std::unordered_map kvpair, bool regex); 14 | #endif // PREPROCESS_JSON_H 15 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Wenzel Jakob , All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | You are under no obligation whatsoever to provide any bug fixes, patches, or 29 | upgrades to the features, functionality or performance of the source code 30 | ("Enhancements") to anyone; however, if you choose to make your Enhancements 31 | available either publicly, or directly to the author of this software, without 32 | imposing a separate written license agreement for such Enhancements, then you 33 | hereby grant the following license: a non-exclusive, royalty-free perpetual 34 | license to install, use, modify, prepare derivative works, incorporate into 35 | other computer software, distribute, and sublicense such enhancements or 36 | derivative works thereof, in binary and source code form. 37 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/fwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | fwd.h -- Forward declarations for path.h and resolver.h 3 | 4 | Copyright (c) 2015 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #if !defined(NAMESPACE_BEGIN) 13 | #define NAMESPACE_BEGIN(name) namespace name { 14 | #endif 15 | #if !defined(NAMESPACE_END) 16 | #define NAMESPACE_END(name) } 17 | #endif 18 | 19 | NAMESPACE_BEGIN(filesystem) 20 | 21 | class path; 22 | class resolver; 23 | 24 | NAMESPACE_END(filesystem) 25 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Steffen Schümann 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/fs_fwd.hpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // 3 | // ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 4 | // 5 | //--------------------------------------------------------------------------------------- 6 | // 7 | // Copyright (c) 2018, Steffen Schümann 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //--------------------------------------------------------------------------------------- 28 | // fs_fwd.hpp - The forwarding header for the header/implementation seperated usage of 29 | // ghc::filesystem. 30 | // This file can be include at any place, where ghc::filesystem api is needed while 31 | // not bleeding implementation details (e.g. system includes) into the global namespace, 32 | // as long as one cpp includes fs_impl.hpp to deliver the matching implementations. 33 | //--------------------------------------------------------------------------------------- 34 | #ifndef GHC_FILESYSTEM_FWD_H 35 | #define GHC_FILESYSTEM_FWD_H 36 | #define GHC_FILESYSTEM_FWD 37 | #include 38 | #endif // GHC_FILESYSTEM_FWD_H 39 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/fs_impl.hpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // 3 | // ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 4 | // 5 | //--------------------------------------------------------------------------------------- 6 | // 7 | // Copyright (c) 2018, Steffen Schümann 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //--------------------------------------------------------------------------------------- 28 | // fs_impl.hpp - The implementation header for the header/implementation seperated usage of 29 | // ghc::filesystem. 30 | // This file can be used to hide the implementation of ghc::filesystem into a single cpp. 31 | // The cpp has to include this before including fs_fwd.hpp directly or via a different 32 | // header to work. 33 | //--------------------------------------------------------------------------------------- 34 | #define GHC_FILESYSTEM_IMPLEMENTATION 35 | #include 36 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/fs_std.hpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // 3 | // ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 4 | // 5 | //--------------------------------------------------------------------------------------- 6 | // 7 | // Copyright (c) 2018, Steffen Schümann 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //--------------------------------------------------------------------------------------- 28 | // fs_std.hpp - The dynamic switching header that includes std::filesystem if detected 29 | // or ghc::filesystem if not, and makes the resulting API available in the 30 | // namespace fs. 31 | //--------------------------------------------------------------------------------------- 32 | #ifndef GHC_FILESYSTEM_STD_H 33 | #define GHC_FILESYSTEM_STD_H 34 | #if defined(__APPLE__) 35 | #include 36 | #endif 37 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) 38 | #if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) 39 | #define GHC_USE_STD_FS 40 | #include 41 | namespace fs { 42 | using namespace std::filesystem; 43 | using ifstream = std::ifstream; 44 | using ofstream = std::ofstream; 45 | using fstream = std::fstream; 46 | } 47 | #endif 48 | #endif 49 | #ifndef GHC_USE_STD_FS 50 | //#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 51 | #include 52 | namespace fs { 53 | using namespace ghc::filesystem; 54 | using ifstream = ghc::filesystem::ifstream; 55 | using ofstream = ghc::filesystem::ofstream; 56 | using fstream = ghc::filesystem::fstream; 57 | } 58 | #endif 59 | #endif // GHC_FILESYSTEM_STD_H 60 | 61 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/fs_std_fwd.hpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // 3 | // ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 4 | // 5 | //--------------------------------------------------------------------------------------- 6 | // 7 | // Copyright (c) 2018, Steffen Schümann 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //--------------------------------------------------------------------------------------- 28 | // fs_std_fwd.hpp - The forwarding header for the header/implementation seperated usage of 29 | // ghc::filesystem that uses std::filesystem if it detects it. 30 | // This file can be include at any place, where fs::filesystem api is needed while 31 | // not bleeding implementation details (e.g. system includes) into the global namespace, 32 | // as long as one cpp includes fs_std_impl.hpp to deliver the matching implementations. 33 | //--------------------------------------------------------------------------------------- 34 | #ifndef GHC_FILESYSTEM_STD_FWD_H 35 | #define GHC_FILESYSTEM_STD_FWD_H 36 | #if defined(__APPLE__) 37 | #include 38 | #endif 39 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) 40 | #if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) 41 | #define GHC_USE_STD_FS 42 | #include 43 | namespace fs { 44 | using namespace std::filesystem; 45 | using ifstream = std::ifstream; 46 | using ofstream = std::ofstream; 47 | using fstream = std::fstream; 48 | } 49 | #endif 50 | #endif 51 | #ifndef GHC_USE_STD_FS 52 | //#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 53 | #define GHC_FILESYSTEM_FWD 54 | #include 55 | namespace fs { 56 | using namespace ghc::filesystem; 57 | using ifstream = ghc::filesystem::ifstream; 58 | using ofstream = ghc::filesystem::ofstream; 59 | using fstream = ghc::filesystem::fstream; 60 | } 61 | #endif 62 | #endif // GHC_FILESYSTEM_STD_FWD_H 63 | 64 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/ghc/fs_std_impl.hpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // 3 | // ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14 4 | // 5 | //--------------------------------------------------------------------------------------- 6 | // 7 | // Copyright (c) 2018, Steffen Schümann 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //--------------------------------------------------------------------------------------- 28 | // fs_std_impl.hpp - The implementation header for the header/implementation seperated usage of 29 | // ghc::filesystem that does nothing if std::filesystem is detected. 30 | // This file can be used to hide the implementation of ghc::filesystem into a single cpp. 31 | // The cpp has to include this before including fs_std_fwd.hpp directly or via a different 32 | // header to work. 33 | //--------------------------------------------------------------------------------------- 34 | #if defined(__APPLE__) 35 | #include 36 | #endif 37 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) 38 | #if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) 39 | #define GHC_USE_STD_FS 40 | #endif 41 | #endif 42 | #ifndef GHC_USE_STD_FS 43 | //#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 44 | #define GHC_FILESYSTEM_IMPLEMENTATION 45 | #include 46 | #endif 47 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/glob/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Pranav 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tools/vvmesh_src/src/filesystem/resolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | resolver.h -- A simple class for cross-platform path resolution 3 | 4 | Copyright (c) 2015 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "path.h" 13 | 14 | NAMESPACE_BEGIN(filesystem) 15 | 16 | /** 17 | * \brief Simple class for resolving paths on Linux/Windows/Mac OS 18 | * 19 | * This convenience class looks for a file or directory given its name 20 | * and a set of search paths. The implementation walks through the 21 | * search paths in order and stops once the file is found. 22 | */ 23 | class resolver { 24 | public: 25 | typedef std::vector::iterator iterator; 26 | typedef std::vector::const_iterator const_iterator; 27 | 28 | resolver() { 29 | m_paths.push_back(path::getcwd()); 30 | } 31 | 32 | size_t size() const { return m_paths.size(); } 33 | 34 | iterator begin() { return m_paths.begin(); } 35 | iterator end() { return m_paths.end(); } 36 | 37 | const_iterator begin() const { return m_paths.begin(); } 38 | const_iterator end() const { return m_paths.end(); } 39 | 40 | void erase(iterator it) { m_paths.erase(it); } 41 | 42 | void prepend(const path &path) { m_paths.insert(m_paths.begin(), path); } 43 | void append(const path &path) { m_paths.push_back(path); } 44 | const path &operator[](size_t index) const { return m_paths[index]; } 45 | path &operator[](size_t index) { return m_paths[index]; } 46 | 47 | path resolve(const path &value) const { 48 | for (const_iterator it = m_paths.begin(); it != m_paths.end(); ++it) { 49 | path combined = *it / value; 50 | if (combined.exists()) 51 | return combined; 52 | } 53 | return value; 54 | } 55 | 56 | friend std::ostream &operator<<(std::ostream &os, const resolver &r) { 57 | os << "resolver[" << std::endl; 58 | for (size_t i = 0; i < r.m_paths.size(); ++i) { 59 | os << " \"" << r.m_paths[i] << "\""; 60 | if (i + 1 < r.m_paths.size()) 61 | os << ","; 62 | os << std::endl; 63 | } 64 | os << "]"; 65 | return os; 66 | } 67 | 68 | private: 69 | std::vector m_paths; 70 | }; 71 | 72 | NAMESPACE_END(filesystem) 73 | -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/utils/__init__.py -------------------------------------------------------------------------------- /utils/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/utils/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /utils/__pycache__/dataset_util.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/utils/__pycache__/dataset_util.cpython-37.pyc -------------------------------------------------------------------------------- /utils/__pycache__/dice_loss.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/utils/__pycache__/dice_loss.cpython-37.pyc -------------------------------------------------------------------------------- /utils/__pycache__/visdataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GDAOSU/vis2mesh/2f273b065e359c8f1d3b1acba00853c6370f8b0f/utils/__pycache__/visdataset.cpython-37.pyc -------------------------------------------------------------------------------- /utils/dice_loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.autograd import Function 3 | 4 | 5 | class DiceCoeff(Function): 6 | """Dice coeff for individual examples""" 7 | def forward(self, input, target): 8 | self.save_for_backward(input, target) 9 | eps = 0.0001 10 | self.inter = torch.dot(input.view(-1), target.view(-1)) 11 | self.union = torch.sum(input) + torch.sum(target) + eps 12 | 13 | t = (2 * self.inter.float() + eps) / self.union.float() 14 | return t 15 | 16 | # This function has only a single output, so it gets only one gradient 17 | def backward(self, grad_output): 18 | 19 | input, target = self.saved_variables 20 | grad_input = grad_target = None 21 | 22 | if self.needs_input_grad[0]: 23 | grad_input = grad_output * 2 * (target * self.union - self.inter) \ 24 | / (self.union * self.union) 25 | if self.needs_input_grad[1]: 26 | grad_target = None 27 | 28 | return grad_input, grad_target 29 | 30 | 31 | def dice_coeff(input, target): 32 | """Dice coeff for batches""" 33 | if input.is_cuda: 34 | s = torch.FloatTensor(1).cuda().zero_() 35 | else: 36 | s = torch.FloatTensor(1).zero_() 37 | 38 | for i, c in enumerate(zip(input, target)): 39 | s = s + DiceCoeff().forward(c[0], c[1]) 40 | 41 | return s / (i + 1) 42 | --------------------------------------------------------------------------------