Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Considering multiple widths in BVHNode construction. Resolves #43 #44

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ project(diffvg VERSION 0.0.1 DESCRIPTION "Differentiable Vector Graphics")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

if(WIN32)
find_package(Python 3.6 COMPONENTS Development REQUIRED)
else()
Expand Down Expand Up @@ -52,6 +54,9 @@ if(NOT DIFFVG_CUDA)
add_compile_options("-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP")
endif()

find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})

set(SRCS atomic.h
color.h
cdf.h
Expand Down Expand Up @@ -118,7 +123,7 @@ elseif(APPLE)
set_target_properties(diffvg PROPERTIES INSTALL_RPATH "@loader_path")
endif()

set_property(TARGET diffvg PROPERTY CXX_STANDARD 11)
set_property(TARGET diffvg PROPERTY CXX_STANDARD 14)
set_target_properties(diffvg PROPERTIES PREFIX "")
# Still enable assertion in release mode
string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
Expand All @@ -130,11 +135,11 @@ string( REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}"
string( REPLACE "/DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string( REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")

if(NOT WIN32)
find_package(TensorFlow)
if(TensorFlow_FOUND)
add_subdirectory(pydiffvg_tensorflow/custom_ops)
else()
message(INFO " Building without TensorFlow support (not found)")
endif()
endif()
# if(NOT WIN32)
# find_package(TensorFlow)
# if(TensorFlow_FOUND)
# add_subdirectory(pydiffvg_tensorflow/custom_ops)
# else()
# message(INFO " Building without TensorFlow support (not found)")
# endif()
# endif()
9 changes: 7 additions & 2 deletions pydiffvg/render_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,13 @@ def backward(ctx,
grad_img):
if not grad_img.is_contiguous():
grad_img = grad_img.contiguous()
assert(torch.isfinite(grad_img).all())

#assert(torch.isfinite(grad_img).all())
print("Backgrad")
try:
assert torch.isfinite(grad_img).all()
except AssertionError:
print("Diffvg Infinite gradient hack. Clamping")
grad_img = torch.clamp(grad_img, -10, 10)
scene = ctx.scene
width = ctx.width
height = ctx.height
Expand Down
6 changes: 6 additions & 0 deletions pydiffvg/save_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def add_color(shape_color, name):
shape_node.set('y', str(shape.p_min[1].item()))
shape_node.set('width', str(shape.p_max[0].item() - shape.p_min[0].item()))
shape_node.set('height', str(shape.p_max[1].item() - shape.p_min[1].item()))
elif isinstance(shape, pydiffvg.Ellipse):
shape_node = etree.SubElement(g, 'ellipse')
shape_node.set('cx', str(shape.center[0].item()))
shape_node.set('cy', str(shape.center[1].item()))
shape_node.set('rx', str(shape.radius[0].item()))
shape_node.set('ry', str(shape.radius[1].item()))
else:
assert(False)

Expand Down
19 changes: 17 additions & 2 deletions scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,20 @@ void compute_bounding_boxes(Scene &scene,
BVHNode *nodes = scene.shape_groups_bvh_nodes[shape_group_id];
for (int i = 0; i < shape_group->num_shapes; i++) {
auto shape_id = shape_group->shape_ids[i];
auto r = shape_group->stroke_color == nullptr ? 0 : shape_list[shape_id]->stroke_width;
float r = 0;
if (shape_group->stroke_color != nullptr){
if (shape_list[shape_id]->type == ShapeType::Path){
const Path *p = (const Path*)(shape_list[shape_id]->ptr);
if (p->thickness != nullptr){
for (int i = 0; i < p->num_points; i++)
r = std::max(r, p->thickness[i]);
}else
r = shape_list[shape_id]->stroke_width;
}else{
r = shape_list[shape_id]->stroke_width;
}
}
//auto r = shape_group->stroke_color == nullptr ? 0 : shape_list[shape_id]->stroke_width;
nodes[i] = BVHNode{shape_id,
-1,
scene.shapes_bbox[shape_id],
Expand All @@ -652,7 +665,9 @@ void compute_bounding_boxes(Scene &scene,
const Path *p = (const Path*)(shape_list[shape_group->shape_ids[0]]->ptr);
if (p->thickness != nullptr) {
const BVHNode *nodes = scene.path_bvhs[shape_group->shape_ids[0]];
max_radius = nodes[0].max_radius;
for (int i = 0; i < p->num_points; i++)
max_radius = std::max(max_radius, p->thickness[i]);
//max_radius = std::max(nodes[0].max_radius, max_radius);
}
}
for (int i = 1; i < shape_group->num_shapes; i++) {
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def build_extension(self, ext):
import torch
if torch.cuda.is_available():
build_with_cuda = True
if tf_spec is not None and sys.platform != 'win32':
if False: #tf_spec is not None and sys.platform != 'win32':
assert(False)
packages.append('pydiffvg_tensorflow')
if not build_with_cuda:
import tensorflow as tf
Expand Down