Skip to content

Commit

Permalink
Merge branch 'master' into release_v6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
akenmorris committed Mar 24, 2023
2 parents 7dab1e4 + cd34447 commit f155ab8
Show file tree
Hide file tree
Showing 29 changed files with 45,103 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Examples/Python/deep_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimizeCmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimizeCmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimizeCmd)

print("To analyze train shape model, call:")
Expand Down Expand Up @@ -533,7 +533,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

print("To analyze validation shape model, call:")
Expand Down Expand Up @@ -690,4 +690,4 @@ def check_results(args, mean_dist):
print("Done with test, verification succeeded.")
exit(0)
else:
return
return
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_multiple_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_multiple_domain_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/femur_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimizeCmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimizeCmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimizeCmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/hip_multiple_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def Run_Pipeline(args):


# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# # If tiny test or verify, check results and exit
Expand Down
4 changes: 2 additions & 2 deletions Examples/Python/incremental_supershapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
print(optimize_cmd)
subprocess.check_call(optimize_cmd)

Expand Down Expand Up @@ -284,7 +284,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' +
optimize_cmd = ('shapeworks optimize --progress --name ' +
spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

Expand Down
5 changes: 3 additions & 2 deletions Examples/Python/left_atrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def Run_Pipeline(args):
parameter_dictionary["multiscale"] = 1
parameter_dictionary["multiscale_particles"] = 128

print('Generating project sheet')
print('Generating project file')
# Add param dictionary to spreadsheet
for key in parameter_dictionary:
parameters.set(key, sw.Variant([parameter_dictionary[key]]))
Expand All @@ -217,7 +217,8 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
print('Running optimization')
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/lumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/peanut_shared_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/supershapes_1mode_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/thin_cavity_bean.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def Run_Pipeline(args):
project.save(spreadsheet_file)

# Run optimization
optimize_cmd = ('shapeworks optimize --name ' + spreadsheet_file).split()
optimize_cmd = ('shapeworks optimize --progress --name ' + spreadsheet_file).split()
subprocess.check_call(optimize_cmd)

# If tiny test or verify, check results and exit
Expand Down
2 changes: 1 addition & 1 deletion Installation/install_python_module.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ REM Installs the shapeworks python module.
REM NOTE: assumes all library dependencies are in this directory\bin

REM install pip module
call pip install Python\shapeworks
call pip install Python\shapeworks.tar.gz

set CONDA_INSTALL_DIR=%CONDA_PREFIX%\lib\site-packages\shapeworks

Expand Down
2 changes: 1 addition & 1 deletion Libs/Analyze/Particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Particles {

vtkSmartPointer<vtkTransform> transform_;
std::vector<vtkSmartPointer<vtkTransform>> procrustes_transforms_;
int alignment_type_;
int alignment_type_ = -1;

};
} // namespace shapeworks
13 changes: 13 additions & 0 deletions Libs/Mesh/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ Mesh& Mesh::applyTransform(const MeshTransform transform) {
return *this;
}

Mesh& Mesh::rotate(const double angle, const Axis axis){

Vector rotation(makeVector({0, 0, 0}));
rotation[axis] = 1;
auto com = center();

MeshTransform transform = MeshTransform::New();
transform->Translate(com[0], com[1], com[2]);
transform->RotateWXYZ(angle,rotation[0], rotation[1], rotation[2]);
transform->Translate(-com[0], -com[1], -com[2]);
return applyTransform(transform);
}

Mesh& Mesh::fillHoles() {
auto filter = vtkSmartPointer<vtkFillHolesFilter>::New();
filter->SetInputData(this->poly_data_);
Expand Down
3 changes: 3 additions & 0 deletions Libs/Mesh/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Mesh {
/// applies the given transformation to the mesh
Mesh& applyTransform(const MeshTransform transform);

/// applies the given rotation to the given axis
Mesh& rotate(const double angle, const Axis axis);

/// finds holes in a mesh and closes them
Mesh& fillHoles();

Expand Down
4 changes: 3 additions & 1 deletion Libs/Optimize/Optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,9 @@ void Optimize::ComputeTotalIterations() {
void Optimize::UpdateProgress() {
auto now = std::chrono::system_clock::now();

if ((now - m_last_update_time) > std::chrono::milliseconds(100)) {
bool final = current_particle_iterations_ == total_particle_iterations_;

if (final || (now - m_last_update_time) > std::chrono::milliseconds(100)) {
m_last_update_time = now;
std::chrono::duration<double> elapsed_seconds =
std::chrono::duration_cast<std::chrono::seconds>(now - m_start_time);
Expand Down
8 changes: 8 additions & 0 deletions Libs/Python/ShapeworksPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,14 @@ PYBIND11_MODULE(shapeworks_py, m)
"applies the given transformation to the mesh",
"transform"_a, "imageTransform"_a=false)


.def("rotate",
[](Mesh& mesh, const double angle, const Axis axis) -> decltype(auto){
return mesh.rotate(angle, axis);
},
"rotate using axis by angle (in degrees)",
"angle"_a, "axis"_a)

.def("fillHoles",
&Mesh::fillHoles,
"finds holes in a mesh and closes them")
Expand Down
7 changes: 6 additions & 1 deletion Python/shapeworks/shapeworks/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ def generate_download_flag(outputDirectory, folder):
#if output/dataset + subfolders exits

dataset = Dataset.from_name(folder)
if dataset == None:
print(f"Error: Unable to locate dataset {folder} on data portal")
raise Exception(f"Dataset {folder} not found on data portal")
if os.path.exists(outputDirectory):
# if the folder is empty or has less than 3 files then download
file_count = count_existing_files(outputDirectory)
print(f"file_count = {file_count}")
print(f"dataset = {dataset}")
if file_count < 6 and dataset:
download_flag = True
elif file_count == 6 and dataset and not("tiny_test" in folder):
download_flag = True
else:
print("Data available in " + outputDirectory + " is sufficient, no new data will be downloaded")
print("Data available in " + outputDirectory + " is sufficient, no new data will be downloaded")
#if the subfolder folder does not exists then download
else:
download_flag = True
Expand Down
13 changes: 6 additions & 7 deletions Support/package_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ cp -r $BUILD/bin/Release bin
rm bin/*Tests.pdb bin/Recon*.pdb bin/Mesh*.pdb
rm -rf Post

# Run auto-documentation
cd $ROOT
PATH=$BUILD/bin/Release/bin:$PATH

# add $PATH to $PYTHONPATH
PYTHONPATH=$PYTHONPATH:$PATH

# Build python packages
for package in DataAugmentationUtilsPackage DatasetUtilsPackage DeepSSMUtilsPackage DocumentationUtilsPackage ShapeCohortGenPackage shapeworks ; do
cd Python
tar czvf ${package}.tar.gz $package
cd ..
done

# Remove tests, they won't work for users anyway
rm bin/*Tests.exe
Expand Down
15 changes: 13 additions & 2 deletions Testing/PythonTests/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@

success = True

def rotateTest():
def rotateTest1():
img = Image(os.environ["DATA"] + "/la-bin-centered.nrrd")
img.rotate(0.7854, [1.0, 1.0, 1.0])

compareImg = Image(os.environ["DATA"] + "/rotate2.nrrd")

return img.compare(compareImg)

success &= utils.test(rotateTest)
success &= utils.test(rotateTest1)

def rotateTest2():
mesh = Mesh(os.environ["DATA"] + "/femur.ply")
mesh.rotate(90, Axis.Y)

compareMesh = Mesh(os.environ["DATA"] + "/rotated_mesh.ply")

return mesh == compareMesh

success &= utils.test(rotateTest2)


sys.exit(not success)

0 comments on commit f155ab8

Please sign in to comment.