# How Breaking My Leg Gave Me Time to Stop and Think

> How I broke my ankle and built set.health, a platform to streamline medical data into amazing healthcare products for patients, doctors and researchers.

[View on manualmeida.dev](https://manualmeida.dev/articles/sethealth-gpu-ct)

Today I'm incredibly excited to show off a project I've been working on, but first a quick back story.

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/ray-tracing.jpg"
      width="1920"
      height="1080"
      loading="lazy"
      decoding="async"
      alt="Ray tracing of my ankle using set.health tech"
    />
  </div>
  <figcaption class="figure-caption">
    <span class="fig-n">Figure 1.</span> Ray tracing of my ankle using
    set.health tech. The loose fragments along the right are the displaced
    pieces of the break.
  </figcaption>
</figure>

I have been writing software since I was 10 years old. Back then, I barely knew what I was doing,
gluing together parts of different videogame websites I loved.

I do remember though the first moment my brain clicked and realized that **programming was more than
putting things together**, but gives you the opportunity to build new things from the ground up. Since
then, it was all about the product, building new things.

When the first iPhone was released, I was fascinated with the idea of building something that could be
used by thousands of people. So I joined an open-source [project to build videogames](https://github.com/cocos2d/cocos2d-objc).
I learned a lot! Computer graphics, teamwork, and how a game engine works under the hood, someone could
say I got my CS "degree" during that time.

This allowed me to build and ship a couple of games, one of them [very successful](https://www.metacritic.com/game/ios/infinity-field),
I worked tirelessly polishing the gameplay, the design of every little aspect, adjusting the difficulty
and the controls obsessively. **It was all about the product**, I didn't care much about the code, it
was a mere tool to accomplish something, but then I fell in love.

**I fell in love with software engineering**, I rediscovered the complexity of building software, the
software itself. The developer experience of people using my code, how an API will be able to scale and
be future proof, optimizing processes so more developers can work without stepping on each other. Since
then, I have worked building SDKs and APIs, created [Gin](/articles/gin-simple-over-easy), and Ionic and
[Stencil](https://stenciljs.com/) using web technologies.

During all this time **I had no time to stop and think**, not a single week without coding, week after
week, then year after year. Thinking more about the "Why", rather than the "How". However, back in
October 2019 something happened. One night some friends and I went out for drinks close to my office in
[Kreuzberg](https://www.google.com/maps/place/Kreuzberg,+Berlin), a vibrant district of Berlin.

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/friends.jpg"
      width="1800"
      height="1350"
      loading="lazy"
      decoding="async"
      alt="My friends in Berlin"
    />
  </div>
</figure>

---

---

---

That night I broke my ankle.

<figure class="figure">
  <div
    class="figure-frame"
    style="display:grid; grid-template-columns:repeat(3,1fr); gap:0.5rem; padding:0.5rem; align-items:center;"
  >
    <img
      src="/articles/sethealth/fracture1.jpg"
      width="800"
      height="1067"
      loading="lazy"
      decoding="async"
      alt="Picture of my ankle"
      style="width:100%; height:auto; display:block; border-radius:2px;"
    />
    <img
      src="/articles/sethealth/fracture2.jpg"
      width="984"
      height="1628"
      loading="lazy"
      decoding="async"
      alt="Sagittal radiography of my ankle"
      style="width:100%; height:auto; display:block; border-radius:2px;"
    />
    <img
      src="/articles/sethealth/fracture3.jpg"
      width="800"
      height="1422"
      loading="lazy"
      decoding="async"
      alt="Coronal radiography of my ankle"
      style="width:100%; height:auto; display:block; border-radius:2px;"
    />
  </div>
</figure>

Suddenly, everything I was doing, I was working on stopped abruptly. For 14 days I "lived" in that
hospital of Kreuzberg, waiting for a surgery until the swelling shrinks. When I was able to calm down,
it was not that bad, I found time to read those books I always wanted to, and books I would have never
read, reconnected with people, wrote more, designed a tattoo for my ankle and even learned some German:
"Ich möchte gerne einen Kaffee mit Milch ohne Zucker". **A time to think and disconnect the autopilot.**

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/tattoo.jpg"
      width="1000"
      height="592"
      loading="lazy"
      decoding="async"
      alt="My tattoo"
    />
  </div>
</figure>

The worst was to come, even though the doctors assured the surgery went well, I had the feeling
something was not good. **After dealing with a very stressful process, I managed to get my health data
onto a CD**, bought an external CD reader on Amazon and asked for a second opinion.

I was told to come back immediately to Spain (where my family is from). Indeed, **there were
problems**, the articular space was not respected, nerve damage because of the suture, an unrepaired
tendon and the syndesmosis screw not placed in the optimal position. I was scared, tired, and
depressed, but after the second surgery I was able to find some peace again.

Without deadlines, I opened my laptop and **remembered those old days where I used to write game
engines and build things**. After some research, I tried to visualize my health data, writing all the
software from scratch.

It was a lot of fun, but how could I [connect the dots](https://www.youtube.com/watch?v=UF8uR6Z6KLc)?

I decided it was time to think again in terms of product, something I would love to build and feel
passionate about.

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/screenshot3.png"
      width="3324"
      height="2222"
      loading="lazy"
      decoding="async"
      alt="Tech demo showcasing my very own ankle"
    />
  </div>
  <figcaption class="figure-caption">
    <span class="fig-n">Figure 2.</span> Tech demo showcasing my very own ankle.
  </figcaption>
</figure>

## Rendering gigabytes of voxels in a browser

A CT scan is a 3D grid of density samples, often hundreds of slices deep, which adds up to gigabytes.
You can't download all of it before drawing anything, and you can't fit all of it in GPU memory. Yet a
radiologist expects to spin and re-window the volume with no lag.

The rendering itself is ray casting through a 3D texture. For each pixel on screen, march a ray into
the volume, sample density along the way, map each sample to color and opacity, and composite front to
back until the pixel goes opaque.

```glsl
// simplified: march a ray through the CT volume and accumulate color + opacity
vec4 raymarch(vec3 origin, vec3 dir) {
  vec4 acc = vec4(0.0);
  for (int i = 0; i < STEPS; i++) {
    vec3 p = origin + dir * (float(i) * stepSize);
    float density = texture(volume, p).r;    // sample one voxel
    vec4 s = transfer(density);              // density -> color + alpha
    acc.rgb += (1.0 - acc.a) * s.a * s.rgb;  // front-to-back compositing
    acc.a   += (1.0 - acc.a) * s.a;
    if (acc.a > 0.99) break;                 // early ray termination
  }
  return acc;
}
```

Three decisions made it run in real time on [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API).
We split each volume into smaller blocks, so the GPU only ever held the parts in view and could skip
the empty space between them. We quantized the data, including the normal vectors used for shading, to
shrink what had to live in texture memory. And we loaded progressively, coarse first and detail as you
leaned in, so the first frame appeared fast even on a multi-gigabyte study.

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/openview.png"
      width="2048"
      height="1336"
      loading="lazy"
      decoding="async"
      alt="OpenView Health, a browser viewer showing a brain MRI in four synchronized panes: axial, coronal, sagittal slices and a 3D angiography render, with measurements and metadata"
    />
  </div>
  <figcaption class="figure-caption">
    <span class="fig-n">Figure 3.</span> OpenView Health, the free viewer we
    built on the set.health SDK. Slices and the 3D render stay in sync, and you
    can measure, window, and annotate straight in the browser.
  </figcaption>
</figure>

## Keeping the data safe by never seeing it

Medical data raises the stakes on security, so we ran end-to-end encryption on the client. A scan never
left the device in the clear, which meant we couldn't read it, and that was the point. The data we
never held unencrypted is data we could never leak. That one decision collapsed a large amount of
compliance and liability surface into something we could reason about.

## Announcing set.health

**Healthcare is not a commodity**, at least it's not for me, so building a health product requires a
strong ethical filter to discard bad ideas. Once you realize that **patients are the true owners of the
data**, but still they can't access it easily, you can see there is a problem. People need a diagnosis
to feel safe and well-informed, to be able to access and share their data and even having access to a
Wifi hotspot is critically important so **they can connect with their loved ones in the emergency
room**.

**Today I am announcing [set.health](https://web.archive.org/web/20200522164645/https://set.health/)**, my bottom-up approach to solve this problem
by helping companies build better software and health products: patient apps, custom implant companies
to ship faster, health platforms to communicate better, [securing the medical data](https://techcrunch.com/2020/01/10/medical-images-exposed-pacs/),
funneling anonymized medical data into [truly open datasets](https://youtu.be/Rp7qqjlBeRY?t=4277)… and
ultimately serve as a product for patients to understand and share their medical data.

There are quite a few companies that also try to solve this problem under different approaches, and I
love it!

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/screenshot5.png"
      width="3324"
      height="2222"
      loading="lazy"
      decoding="async"
      alt="Screenshot of a COVID19 case, showing pneumonia"
    />
  </div>
  <figcaption class="figure-caption">
    <span class="fig-n">Figure 4.</span> Technical demo of a COVID19 case using
    set.health directly from a browser.
  </figcaption>
</figure>

## What it became

set.health shipped as an SDK and a compliant backend across iOS, Android, and the web, and it ran until 2026. The use case that clicked was custom prosthetics. A doctor could shape an implant against a
patient's real anatomy, an engineer could validate it, and the two could hold a precise conversation
inside the same 3D view, all running on our SDK.

<figure class="figure">
  <div class="figure-frame">
    <img
      src="/articles/sethealth/custom-implants.png"
      width="1270"
      height="761"
      loading="lazy"
      decoding="async"
      alt="A custom-implant ordering tool built on the set.health SDK, showing a fractured ankle with surgical plates and screws planned over the CT scan, alongside controls to order implants, surgical guides, and 3D-printed bio-models"
    />
  </div>
  <figcaption class="figure-caption">
    <span class="fig-n">Figure 5.</span> A custom-implant planning and ordering
    tool a partner built on the SDK: plan plates, screws, and surgical guides
    against a real fracture, leave notes, and order the printed parts. The tool
    is no longer online.
  </figcaption>
</figure>

2020 is being a complicated year for all of us, but _It Gets Worse Before It Gets Better_. Today, I can
say that breaking my ankle might be one of the 5 best things that happened in my life, just time will
say in which position exactly.

Please [take a look](https://web.archive.org/web/20220427060057/https://set.health/), and send me an
[email](mailto:manu@manualmeida.dev) if you wanna know more, I would love to heard from you!

_set.health is no longer online — those links go to how the site looked the week I published this._

**Tschüss** 👋

---

## About the author

Manuel Martínez-Almeida (Manu) is a principal engineer at Builder.io, where he sets the technical direction for the AI agent platform across product, design, and code. He is the creator of Gin (the Go web framework with ~88k GitHub stars and 290k+ dependent projects), helped take Qwik from proof-of-concept to production including its Rust compiler and resumability model, and designed the compiler architecture and virtual DOM for Stencil. His work sits where performance, systems, and developer experience meet — compilers, language runtimes, web frameworks, GPU rendering, and distributed infrastructure serving billions of requests a day. He is based between Lisbon and Budapest.

- **Name:** Manuel Martínez-Almeida (Manu)
- **Role:** Principal Engineer at Builder.io
- **Focus:** compilers, language runtimes, web frameworks, GPU rendering, distributed infrastructure, developer experience, AI agents, open source
- **About:** https://manualmeida.dev/articles/about/
- **GitHub:** https://github.com/manucorporat
- **Twitter/X:** https://x.com/manucorporat
- **dev.to:** https://dev.to/manucorporat
- **Website:** https://manualmeida.dev
